English 中文(简体)
我如何可靠地把记忆放到桌面上?
原标题:How do I reliably release memory in iPhone app?
最佳回答

th的一般规则,如果你称之为一种帮助器静态方法(例如<条码>,显示ByAppendingString),那么你就应当予以释放。 在发给你之前,在自动释放库中添加了该插座。 请打电话alloc 然后是init......,则由您负责释放该物体。

贵国法典中的其他内容:

  • In the second example, you alloc postData, then immediately replace it with another string created by stringByAppendingString, that is a memory leak.
  • Your release calls are wrong, they should be [postData release] and [request release]
  • I don t see any correlation between postData and request in your example, so not sure exactly what you are getting at with the two of them.
问题回答

第一,在你的第二个例子中,<编码> 数据 = [NSString alloc];是完全没有必要的——postData由下行文撰写。 第二,为了回答您的问题,即为什么事情失事——没有很好的答案——系统可以选择在预留的点击之后永远放弃记忆。 页: 1 为了更方便地解答这一问题,请在NSZombieEnabled上转播任何已分配的物体,使你能100%可靠地测试坠毁。

而且,单行各行各行各行各行各行各行各行各行各行各行各样。

总的来说,你应侧重于遵循记忆准则。 如果你不遵循这些准则,行为就可能不明确。

给您的物体留下记忆,使其在单一行文中更好地发挥作用——固定式方法可以退回不同的物体,也可有助于避免你在第二例中误写:

NSString *postData; // Define pointer to string
postData = [NSString alloc]; // Allocating nsstring pointer and assign it to variable
postData = [@"foo=" stringByAppendingString:fooText.text]; // assign to postData new **autoreleased** string object. result of the previous assignment is abandoned.
[postData release];  //so here you release autoreleased object!!

我无法说明为什么[遗嘱释放];在第一个例子中造成坠毁。

P.S. I m 不是完全醒过来,而是应该打上<条码>[海报发布],而不是<条码>。

NSString *postData;
postData = [[NSString alloc]init];
postData = [@"foo=" stringByAppendingString:fooText.text];
...
NSMutableURLRequest *request;
request = [[NSMutableURLRequest alloc]initWithURL:url];
...
    [postData release];   
    [request 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风格的解决办法,只是一个简单的袖珍流程......

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

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

热门标签