Q:

Yet Another IPhone Memory Management Question

So say I'm getting results from my core data request: (this is example code)
On a button press event it does:
NSMutableArray *results = [[myContext executeFetchRequest:request error:&error] mutableCopy];
myObject = (MyObject *)[mutableFetchResults1 objectAtIndex:0]; // assume that there's something in there

Now I want myObject to stick around for awhile in my program... i.e., the information contained in 'myObject' will be used in other events and such. So I have it defined in my .h file. 
My question is, how do I manage memory in this case. Do I need to 'release' results or myObject at some point? Instruments is saying that this is leaking... But do you see any problems here?

A:

You can just do a retain on the 0 index object from the results like so:
myObject = [(MyObject *)[mutableFetchResults1 objectAtIndex:0] retain];

And then you could release results right after that, myObject would hang around.  You would then later need to release myObject as well.

