English 中文(简体)
如何更好地处理临时扼杀?
原标题:What is the better way of handling temporary strings?

我有这样一种情况,即我需要暂时使用一些扼杀,但我已读到如此多的相互冲突的东西,而我却对下一步工作的最佳方式感到困惑。

如果结构内部存在某些限制,但如果结构之外使用,那么,如果我想到的是:

NSString *arbString = [[NSString alloc] init];

if(whatever)
{
    arbString = @"Whatever"
}
else
{
    arbString = @"SomethingElse"
}

myLabel.text = arbString;
[arbString release];

我看到了人们刚才使用的例子:

NSString *arbString;

A. 创建星座变量

谷歌目标 《指南》说,它倾向于在设定时自动释放:

“在制造新的临时物体时,自动释放这些物体与制造这些物体的相同,而不是以相同方法稍后单独释放”:

// AVOID (unless you have a compelling performance reason)
MyController* controller = [[MyController alloc] init];
// ... code here that might return ...
[controller release];

// BETTER
MyController* controller = [[[MyController alloc] init] autorelease];

因此,我没有想法,什么是最佳做法?

最佳回答

在你所举的例子中,你实际上没有提及你在<代码>arbString = @`Whatever'上指定时创建的国家统计系统。 之后,你释放了扼杀的常数(这是不可阻塞的)。

因此,记忆中漏掉,因为你永远不会释放你创建的国家安全局。

认为所有这些类型都是点码,因此=只重新调配。

就此而言,你不需要<条码>。 无需将插图复制成一个地方变量,你只能设置myLabel.text/code>至“string persistent @“Whatever”

(编辑:不说你可以使用你的点代码,arbString = @Whatever”;我的Label.text = arbString。 但这只是点任务,而不是复制。

如果在你回来之前需要操纵扼杀,你就会形成一种安全感,释放或自动释放。 个人使用等级方法制造自动释放的物体,例如,我使用<代码>[NSString string]。 缩略语:], 归还自动释放物体。

问题回答

暂无回答




相关问题
Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple s built-in iSight? I ve seen lots of tutorials on recording video but none on simply taking a picture. Any ...

Controlling OSX windows

I m trying to control windows of a foreign OSX applications from my application. I d like to 1. move the windows on the screen 2. resize the windows on the screen 3. change the currently active window ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

How to get a flash url in a webpage using a webframe?

As we know , When we load frame from webpage of safari, we will invoke the delegate methods of webkit informal protocol(WebFrameLoadDelegate): webView:didStartProvisionalLoadForFrame: webView:...

热门标签