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