English 中文(简体)
目标C. 国家航空航天研究所的记忆管理问题
原标题:Objective C memory management question with NSArray

我装载着像这样的浮体:

NSArray *arr= [NSArray arrayWithObjects:
                [NSNumber numberWithFloat:1.9],
                [NSNumber numberWithFloat:1.7],
                [NSNumber numberWithFloat:1.6],
                [NSNumber numberWithFloat:1.9],nil];

现在我知道这是这样做的正确方式,但零售价令我感到困惑。

  1. 每人 反对由<代码>[NSNumber number WithFloat:]方法确定。 这使该物体保留了1只手套? - 否则,该物体将被收回

  2. www.un.org/Depts/DGACM/index_french.htm 方法向每个物体发出保留信息。

这意味着每个物体均保留2号。 当阵列被拆除时,每个物体均被释放,然后保留1个。

我错了什么?

最佳回答

The NSNumber number WithFloat: methods isn t re atay Object.

In general unless you re using alloc, copy or new you can presume that you re getting a object that has a retain count of zero. As such the only retain that s taking place is when the NSArray has the objects added to it.

http://interfacelab.com

问题回答

There is no need to release those objects.
The arrayWithObjects: and numberWithFloat: creates object you do not own.





相关问题
Windows Mobile 6 Emulator change storage?

How do i change the size of the Windows Mobile 6 Emulator. Its fixed at 32mb. I read this post: Increasing Windows Mobile 5 Emulator Storage But it only helps for the 5.0 version. Isnt there any way ...

CUDA Memory Allocation accessible for both host and device

I m trying to figure out a way to allocate a block of memory that is accessible by both the host (CPU) and device (GPU). Other than using cudaHostAlloc() function to allocate page-locked memory that ...

RAM memory reallocation - Windows and Linux

I am working on a project involving optimizing energy consumption within a system. Part of that project consists in allocating RAM memory based on locality, that is allocating memory segments for a ...

Should I send retain or autorelease before returning objects?

I thought I was doing the right thing here but I get several warnings from the Build and Analyze so now I m not so sure. My assumption is (a) that an object I get from a function (dateFromComponents: ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

doubts regarding Memory management in .net

I m learning about Memory management in C# from the book "Professional C#" The presence of the garbage collector means that you will usually not worry about objects that you no longer need; ...

Objective-C returning alloc d memory in a function == bad?

This is on the iPhone. So what if I have a function like - (SomeObject*)buildObject; Do I need to pass in a variable that I have already alloc d outside like - (void)assignObject(SomeObject** out);...

热门标签