autorelease

Is return autorelease a bug in objective c?

I am new to objective c and am trying to understand how/when autorelease is called. I understand the simple use case of: - (void) foo { Bar *b = [[[Bar alloc] init] autorelease]; [self doSomething:b]; } What about this next case -- is this a bug, because the object will be immediately released upon leaving the scope of makeB...

TableViewCell autorelease error

OK, for two days now i have been trying to solve an error i have inside the cellForRowAtIndex method, let start by saying that i have tracked down the bug to this method, the error is [CFDictionary image] or [Not a Type image] message sent to deallocated instance. I know about the debug flags, NSZombie, MallocStack, and others, they h...

retain object in objective-c

I'm doing a set method: OBS: somobject is an attribute of a class. – (void)setSomeObject:(SomeObject *)newSomeobject { [someobject autorelease]; someobject = [newSomeobject retain]; return; } on [somobject autorelease] I declare that I don't want more to own the object under the scope of setSomeObject. Does the "som...

Returning objects with autorelease but I still leak memory

I am leaking memory on this: my custom class: + (id)vectorWithX:(float)dimx Y:(float)dimy{ return [[[Vector alloc] initVectorWithX:dimx Y:dimy] autorelease]; } - (Vector*)add:(Vector*)q { return [[[Vector vectorWithX:x+q.x Y:y+q.y] retain] autorelease]; } in app delegate I initiate it: Vector *v1 = [[Vector alloc] initVector]; Vec...

when an autoreleased object is actually released?

Hi, I am new in objective-c and I am trying to understand memory management to get it right. After reading the excellent Memory Management Programming Guide for Cocoa by apple my only concern is when actually an autoreleased object is released in an iphone/ipod application. My understanding is at the end of a run loop. But what define...

Is it dangerous to set off an autoreleased NSOperationQueue?

I have a task that takes a rather long time and should run in the background. According to the documentation, this can be done using an NSOperationQueue. However, I do not want to keep a class-global copy of the NSOperationQueue since I really only use it for that one task. Hence, I just set it to autorelease and hope that it won't get r...

returning autorelease NSString still causes memory leaks

I have a simple function that returns an NSString after decoding it. I use it a lot throughout my application, and it appears to create a memory leak (according to "leaks" tool) every time I use it. Leaks tells me the problem is on the line where I alloc the NSString that I am going to return, even though I autorelease it. Here is the...

Do autoreleased objects always survive a whole method?

Hi, If I'm correct then the releasing of the pool of autoreleased objects has something to do with the run loop.. I barely have an idea of what that 'run loop' is but my question is, is it possible that the object gets released before the end of the method is reached? ...

Can I early-release an autorelease object?

i.e. would cause the object to be released immediately and not have to be released by the pool if I did this? [[NSArray arrayWithCapacity:100] release]; Can't find a clear explanation in the docs about this. ...

Objective-C autorelease pool not releasing object

Hi 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...

Using NSThread to solve waiting for image from URL on the iPhone

So I have the following code in a method which I want to set a UIImageView image to that of one from an online source: [NSThread detachNewThreadSelector:@selector(loadImage) toTarget:self withObject:nil]; Then in the method called by the thread I have this: - (void) loadImage { NSURL *url = [NSURL URLWithString:logoPath]; // logo...

Why am I getting *** _NSAutoreleaseNoPool(): Object 0x97480b0 of class NSCFDictionary autoreleased with no pool in place - just leaking.

I have noted several other threads on this topic and have tried wrapping my threaded code with: NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; [pool release]; but the errors still come. I am using a static method to instantiate a dictionary of words. Here is some code: -(id)init [NSThread detachNewThreadSelector...

Object sent -autorelease too many times

I have this code that simple returns Today's date as a string formatted: +(NSString*) getTodayString_YYYY_MM_DD { NSDate * today = [NSDate date]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd"]; return [[formatter stringFromDate:today] autorelease]; } With instrument...

autorelease previous object by assignment

If I have a function like this void setSomeObject( SomeObjectClass obj /*, and some other params*/ ) { [_previous autorelease]; _previous = obj; } As far as I understood it the autorelease message is sent to the object itself (not _previous) so at one point, sometime when setSomeObject goes out of scope the original object is auto...

Memory leak with autoreleased strings iphone

Hi, I'm trying to clean my app from leaks with Leak instrument. It shows me leaks on xml parser (TBXML). Here is a class I'm going to create upon the parsing: @interface GraphPoint : NSObject { NSString* x; NSString* y; } @property (nonatomic, copy) NSString* x; @property (nonatomic, copy) NSString* y; @end @implementation...

Releasing while notifying

Hi there!, I have an object id currentObject; which I want to pass through notification. The problem is I don't know how to release it correctly and the memory management documentation is driving me crazy. I am doing it like this right now: [[NSNotificationCenter defaultCenter] postNotificationName:@"MessageReceived" object:nil us...

Why is this NIB view not released before being returned?

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"ThemeCell" owner:self options:nil]; cell = self.themeCell; self.themeCell = nil; } ... return cell; My understanding is that self.themeCell = nil; should destroy the object sinc...

How to autorelease in Objective - c.

Hi, I'm not using Autorelease. When I use like this code, I don't know How to release BSPTile NSUInteger numbToday = [[dateFormatter stringFromDate:[NSDate date]] intValue]; BSPTileView *tile = [gridView.subviews objectAtIndex: 0]; tile.comparedValue = 0; BSPTileView is UIView Class. How to do ? please. ...

Retain count for tableView:cellForRowAtIndexPath:

In Apple's example code, the method tableView:cellForRowAtIndexPath: of a UITableViewDataSource returns a cell with a retain count of 1; it allocs it, but doesn't autorelease it. However, the static analyzer complains that this violates the Cocoa naming conventions, since the method name doesn't start with 'new', etc. The documentation d...

Class Methods Used Many Times Cause Leaks?

Let's say I'm developing a game. I run the following class method thousands of times: NSBundle *bundle=[NSBundle mainBundle]; I do not create an autorelease pool and release the objects that call the above class method all the time. I create an object, it calls the above class method, I release it, and on, and on, thousands of times. ...