nsautoreleasepool

Objective-C autorelease pool not releasing object

做~自己de王妃 提交于 2019-12-20 02:46:31
问题 I am very new to Objective-C and was reading through memory management. I was trying to play around a bit with the NSAutoreleasePool but somehow it wont release my object. I have a class with a setter and getter which basically sets a NSString *name. After releasing the pool I tried to NSLog the object and it still works but I guess it should not? @interface TestClass : NSObject { NSString *name; } - (void) setName: (NSString *) string; - (NSString *) name; @end @implementation TestClass -

When does autorelease actually cause a release in Cocoa Touch?

做~自己de王妃 提交于 2019-12-18 12:36:31
问题 I understand you need to be careful with autorelease on iOS. I have a method that is returning an object it alloc s which is needed by the caller, so in this situation -- as I understand it -- I need to send autorelease to the object in the callee before it returns. This is fine, but once control returns to the phone (i.e. after my button click has been processed) it seems that the autorelease pool is released. I suspect this is how it is supposed to be, but I am wondering what is the best

End of run loop — autorelease pool recovery

大城市里の小女人 提交于 2019-12-18 10:46:39
问题 As I understand, autoreleased objects are cleaned once an autoreleased pool is released. Now, autorelease pool will be released at the end of the run loop. My question is, if in my class I am not creating a custom autorelease pool and calling the autorelease method on some objects in that class, at what point will those objects be recovered? Is the "end of the run loop" imply the "end of application"? 回答1: You have to understand the concept of a run-loop. The run loop in iOS waits for some

Why use Autorelease pool?

吃可爱长大的小学妹 提交于 2019-12-18 10:41:39
问题 I know there is an autorelease pool created in the main method and all the objects that receive autorelease message get stored in this pool and get released when the pool drains out. But it is always said to avoid autoreleasing objects to avoid memory leaks and in turn app crashes. Then why and in which conditions should we use autoreleasepool? Apple docs suggest that we need to use them when we are using threads so in the beginning of a thread we need to create an autorelease pool and in the

NSAutoreleasePool is unavailable

别来无恙 提交于 2019-12-17 16:25:06
问题 I am following "Programming in Objective-C" 3 rd edition and I am having problems with the first example. I keep getting this error: Semantic Issue: 'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode Here is my code: // // main.m // prog1 // // Created by Steve Kochan on 1/30/11. // Copyright 2011 ClassroomM, Inc.. All rights reserved. // #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [

How does the NSAutoreleasePool autorelease pool work?

我的未来我决定 提交于 2019-12-17 02:58:14
问题 As I understand it, anything created with an alloc , new , or copy needs to be manually released. For example: int main(void) { NSString *string; string = [[NSString alloc] init]; /* use the string */ [string release]; } My question, though, is wouldn't this be just as valid?: int main(void) { NSAutoreleasePool *pool; pool = [[NSAutoreleasePool alloc] init]; NSString *string; string = [[[NSString alloc] init] autorelease]; /* use the string */ [pool drain]; } 回答1: Yes, your second code

Crash at _CFAutoreleasePoolPop

江枫思渺然 提交于 2019-12-13 07:32:17
问题 I got a crash from Fabric ,the stack is below: Thread : Crashed: com.apple.main-thread 0 libobjc.A.dylib 6806634868 objc_release + 20 1 libsystem_blocks.dylib 6813456656 _Block_release + 256 2 libobjc.A.dylib 6806640420 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 564 3 CoreFoundation 6529519172 _CFAutoreleasePoolPop + 28 4 UIKit 6605817924 _wrapRunLoopWithAutoreleasePoolHandler + 76 5 CoreFoundation 6530394704 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32 6

how to properly use autoreleasepool for an nsoperationqueue

狂风中的少年 提交于 2019-12-12 18:41:35
问题 I have an app that I am refactoring and I just implemented multithreading so that the UI may run smoother. In the iphone simulator I don't get any leaks but testing on my iPhone 3G running on iOS 4.2 I get a memory leak. I have done a lot of searching for the correct way to implement an autoreleasepool with an operationqueue, help will be greatly appreciated. I have created an nsoperationqueue in my viewcontroller as such - (void)loadData { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]

NSTableView reloadData leaking memory

╄→尐↘猪︶ㄣ 提交于 2019-12-12 04:42:01
问题 I've been checking my application for leaks using the Instruments application. Under a certain set of circumstances a table view in a HUD Panel is being updated once a second. It is all working fine except every second (reloadData) the number of _NSArrayl objects increases by one. If I change my datasource to just a return(@""); (they are all text cells) then the problem stays (no change). If I remove all my surrounding code to just: [myTableView reloadData]; and - (id)tableView:(NSTableView

Error at NSRunLoop after returning from thread method with NSAutoreleasePool

陌路散爱 提交于 2019-12-12 01:37:31
问题 I am getting an EXC_BAD_ACCESS error after I return from a thread method in which I have set up an NSAutoreleasePool. The place of failure is at a call to NSRunLoop. I am trying to wrap a 3rd party library consisting mainly of a class (let's call it the Connection class) and its delegate such that it will behave synchronously instead of asynchronously to client classes. The wrapping class, called NFCConnection, conforms to the delegate protocol and is passed to Connection's setDelegate method