English 中文(简体)
如何正确纪念和释放英语
原标题:Whats the correct way to alloc a UIImage to memory and release it iphone

Using Instruments, I keep on getting pointed to a memory leak with a UIImage.
I think I m assigning and releasing the memory correctly. The leaked object in instruments is described as NSConcreteData

分配和释放UIImage的以下正确方式吗?

UIImage* flagimg = [UIImage imageWithData: [NSData dataWithContentsOfURL:url2]];    
[flagimg release];
flagimg =nil;
最佳回答

<代码> WithData:] Return an autoreleased Object, which should not be release by You. 因此,这部法典没有包含记忆泄露,而是相反的,是双重自由(在最坏的情况下)。

请注意,文书有时产生虚假的正面和(或)报道基金会本身的记忆泄露(大概,错误也造成:-)。

一切物体/发射最快的办法是避免方便的初始器(如图像WithData:)和像样的物品。

NSData* data = [[NSData alloc] initWithContentsOfURL:url]];
UIImage* img = [[UIImage alloc] initWithData:data];
[data release];
// use your image
[img release];

这将分配和释放你们的物体,直至清理汽车库。

但是,也请指出,记忆泄露一般不是免费的yet<>m>,而是丢失的,而且不能再放开<>>,因此,由自动取款库处理的一个物体不被视为记忆泄。

问题回答

作为一般规则,你可以说

if you create an object an theres a "init","copy" or "retain" in it, you have to release it. if not, you get an autoreleased object.

这并不总是真实的,但在大多数情况下都是如此。

<代码>mageWithData和data WithContentsOfURL 自动释放的物体,因此,在《代码》中,不应出现任何传闻。

由于<代码>flagimg已自动发布,您的<代码>[flagimg release]; 无须打电话;您重新接过该物体。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。