autorelease

Releasing objects returned by method in Objective-C

Ok, I know the answer to this question should be obvious, but I need a little push in the right direction. I find myself writing a fair number of methods that follow the following pattern: -(NSThing*)myMethod{ NSThing *thing = [[NSthing alloc] init]; // do some stuff with the thing return thing; } My question is, how do I hand...

Returning object initialized through "convenience constructor"

When an instance method returns a value that was initialized with a convenience constructor, do I need to retain that object and then autorelease in the return so that when the convenience constructor's autorelease occurs, it doesn't remove the object. Will this release description before the calling code and take ownership with a retai...

Objective-C on GNUstep AutoReleasePool undeclared problem

I'm new to Objective-C and working in GNUstep and MinGW environment. I am compiling this code but having an error: #import "Foundation/Foundation.h" @interface C : NSObject { float f; } - (void) gamerHell: (NSString *) name : (NSString *) lastName ; @end @implementation C - (void) gamerHell: (NSString *) firstName : (NSString *...

Releasing autorelease object does not crash my app why?

why app does not crash when i release any autorelease object, or is it that my app will crash some time later when autorelease pool is drained? ...

stringWithContentsOfURL leaking memory

Would it shed more light if I told that fetchHTML was being called in a seperate thread? I am also seeing several messages in the debug console such as: _NSAutoreleaseNoPool(): Object 0xd92860 of class NSCFDictionary autoreleased with no pool in place - just leaking _NSAutoreleaseNoPool(): Object 0xd92800 of class NSCFString autoreleas...

What is the scope of (nested) autorelease pools?

Hello, I'm creating an autorelease pool in a for loop (in method A). At each iteration of the loop, I'm calling another method (method B). Method B returns an autoreleased object to Method A. If I drain the pool within the for loop in Method A, will that release the objects sent from Method B? Thanks! ...

My code either leaks and works, or doesn't leak and crashes. This doesn't seem like an autorelease problem...

After I finished coding the difficult parts of my game, I found some memory management bugs. objects is a NSMutableArray holding a custom class. - (void) spawnObjects { for (int index = 0; index < INITIAL_OBJECTS; index++) { [objects addObject:[[[MatchObject alloc] initWithImageNameID:(index % 3)] autorelease]]; ...

How to know if an object is autoreleased or not?

I'm getting a a bit annoyed about some objects being autoreleased without me knowing. It's probably a good thing that they are, but if they are, I want to know. The documentation doesn't say which methods autorelease objects, so I usually test my way forward, which in my opinion is silly. For example, [NSDate date] autoreleases the objec...

Iphone open gl es application and autorelease pool

So I am creating my first opengl es application on the iphone. I want to autorelease an object and that was around the time I noticed that I can't seem to find the location of the autorelease pool. 1) Is the autorelease pool already created for me in an iphone opengl es application? 2) If it is already created for me how often is the ...

how to find objects with autorelease message?

Hi My application crashes when the autorelease pool is released. The reason seems to be that the object with autorelease message is sent a release message sometime before the pool is released, hence the application crashes for object which is already released. Hence I want to find which objects have a pending autorelease message, so t...

autorelease pool causes crash in RubyCocoa application

Hi, I'm having crash in my application, which says trying to pop an unknown autorelease pool: 10/19/09 11:40:11 AM MyApp[89480] *** attempt to pop an unknown autorelease pool (0x11bc800) How to trace it down? Since it's RubyCocoa application it's almost impossible to trace it with gdb in Xcode environment. So mostly it's about loggin...

iPhone SDK: How/when should I release a UITableView delegate object?

I am using a custom class as the delegate and datasource on a UITableView. I'm doing (something like) this in my viewDidLoad method: MyClass *myObject = [[MyClass alloc] init]; tableViewOutlet.delegate = myObject; tableViewOutlet.dataSource = myObject; Surely I need to decrease the retain count on myObject somewhere? But calling [my...

Creating autorelease objects in iPhone Development

I have a requirement to create some NSDecimalNumber objects objects as part of my application (as I require the precision of calculation they offer) but I note that in calculations they return NSDecimalNumber objects which are, presumably, autoreleased. My question is really whether this is potentially problematic in an iPhone applicat...

Creating NSDecimal

I am carrying out a number of calculations using NSDecimal and am creating each NSDecimal struct using the following technique: [[NSNumber numberWithFloat:kFloatConstant] decimalValue] I am using NSDecimal to avoid using autoreleased NSDecimalNumber objects (if the NSDecimalNumber approach to accurate calculations is used). However it...

iPhone memory leak help

This code is leaking, the performance tool blames two leaks on this block of code. If i comment it out the leak doesn't happen. Any help pinning it down would be greatly appreciated. Leaks: Malloc 48 bytes NSCFarray 32 bytes Code Block: NSArray *myArray = [[NSArray alloc] initWithObjects: @"Add", @"Edit", nil]; segmentContro...

How to force release an UITableViewCell

Is there a way to force a custom UITableViewCell to be released instead of waiting for the OS to autorelease it later? ...

NSURLCache crashes with autoreleased objects, but leaks otherwise...

UPDATE: After submitting a radar to Apple it appears that this is a known issue (Radar #7640470). CSURLCache is designed to cache resources for offline browsing, as NSURLCache only stores data in-memory. If cachedResponse is autoreleased before returning the application crashes, if not, the objects are simply leaked. Any light that co...

Objective-C memory management (alloc and autorelease)

When you allocate and initialize and object, and then want to return that object, how are you supposed to return it? I have the following code: NSXMLDocument* fmdoc = [[NSXMLDocument alloc] initWithContentsOfURL:trackInfoUrl options:NSXMLDocumentTidyXML error:&err]; return [fmdoc autorelease]; Is this correct? ...

Objective-C memory management strange results

I am calling a function repeatedly with a loop, and the loop runs inside of a thread. The thread has an autorelease pool. I have the following code inside that function: NSXMLDocument* undoXML; NSData* undoData = [NSData dataWithContentsOfFile:undoFilePath]; undoXML = [[NSXMLDocument alloc] initWithData:undoData opti...

What is the correct way to Manage memory in an iPhone app for an instance variable that is frequently reassigned to newly allocated memory?

I'm having trouble figuring out how to manage memory for an instance variable that needs to maintain it's current state for a period of time, then be reassigned to newly allocated memory. Take the following example for the instance variable "importantData".: -(void)Update { importantData = [[self getObject] retain]; } - (SomeObjec...