English 中文(简体)
标 值
原标题:Copy Object Values

我有一套办法接收一个阵列,然后在NSO物体中储存。

- (void)updatePoints:(NSArray *)pointArrayPassed
{
    pointArray = pointArrayPassed;
    pointCount= pointArray.count;
}

下面的法典是行之有效的,但显然保留了ArrayPassed的点子,这样,我就可以把这个点 reflects倒。 然而,如果我使用ArrayPassed号的复印件,那就开始大量泄漏!

职能中是否有办法只通过这样的价值观而不是点子?

最佳回答

你可以不释放目前的物体,而只是把复制件贴在单瓦拉。 否则,你就失去了可以发送<代码>release电文的发号人,这就是为什么电文遍布各地。

这是更好的替代。

- (void)updatePoints:(NSArray *)pointArrayPassed
{
    if (pointArray == pointArrayPassed) {
        //the new array is the same as the current one. Do nothing
        return;
    }
    [pointArray release];
    pointArray = [pointArrayPassed copy];
    pointCount = pointArray.count;

}

But it s not the most elegant way of doing it.

更好的办法是将Array作为财产申报如下:copy,作为其记忆管理周期(很明显,因为你有一个可变/可变的分类组)。 还有一种称为<代码>-pointCount的单独方法,必要时可重新计算。

问题回答

暂无回答




相关问题
Duplicate a table row with UITableViewCellEditingStyleInsert?

I have an application based on the Core Data Books example, and I m coming to the conclusion that I need to give the user the ability to duplicate a row in the table - a set of data - and then let ...

Copy/Paste in Windows Forms with custom controls

I am writing a small application in C# using Windows Forms. I want to let my users copy and paste data around the application and there are some custom controls, for example one is a colour picker. ...

Copying only non-existent files in ant

I m deploying my project to a web-server to be deployed with java Web Start. However, Web Start uses modification date to figure out whether to download the resources again (by default). What I want ...

Copying one FlowDocument to Second FlowDocument

How can i copy the contents of one FlowDocument to another FlowDocument below is what i tryed foreach (var blk in fd1.Blocks) { fd2.Blocks.Add(blk); } fd1 is FlowDocument1 and fd2 is ...

emacs command to append to ring

How can I make an emacs command to copy text (to the kill ring) by appending? (Why is there no such built-in command?) Appending Kills mentions C-M-w (`append-next-kill ) which allows me to append ...

about get value from sqlite

Code Sample: NSString *str= [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 1)]; Test *t=[[Test alloc] init]; t.str=[str copy]; // why use "copy" here? [str release];

Insert into an STL queue using std::copy

I d like to use std::copy to insert elements into a queue like this: vector<int> v; v.push_back( 1 ); v.push_back( 2 ); queue<int> q; copy( v.begin(), v.end(), insert_iterator< queue&...

热门标签