Object Release Difficulty
Okay, I have two objects.
All that I do to john is Allocate and Initalise it
and release it
I don't do anything at all to environment, bar the single line I've already shown. (I've gone through every file in my program both looking by eye and doing a find).
However, when I comment out or delete the line "Surroundings *environment;" I get an EXC_BAD_ACCESS error when trying to release john.
This just seems bizzare to me; anybody else have any ideas?
Cheers,
Mark
Code:
Surroundings *john;
Surroundings *environment;All that I do to john is Allocate and Initalise it
Code:
john = [[Surroundings alloc] init];and release it
Code:
[john release];I don't do anything at all to environment, bar the single line I've already shown. (I've gone through every file in my program both looking by eye and doing a find).
However, when I comment out or delete the line "Surroundings *environment;" I get an EXC_BAD_ACCESS error when trying to release john.
This just seems bizzare to me; anybody else have any ideas?
Cheers,
Mark
Show us your Surroundings class's -init method.
It's just this at the moment:
I didn't think I needed any more than that for what I've done so far...
-Mark
Code:
- init
{
self = [super init];
if(self == nil)
return nil;
return self;
}I didn't think I needed any more than that for what I've done so far...
-Mark
Are you positive that your allocation code is being called? Made sure that you're not releasing more than once? Put john in an array and released the array (calling release on each contained object)?
I'm honestly not doing anything with john that hasn't been listed above.
As far as checking that my allocation method is called, I've gone:
And it didn't say what's in my NSLog statement. I was assuming that was enough - Maybe not?
As far as checking that my allocation method is called, I've gone:
Code:
if(!(john = [[Surroundings alloc] init]))
NSLog(@"Oh no! john didn't alloc!");And it didn't say what's in my NSLog statement. I was assuming that was enough - Maybe not?
This kind of thing usually shows up if you're trashing your stack somewhere. It's often an annoyingly difficult problem to debug. Try printing out the value of john after you alloc it, and again just before you release it, and see if it changes unexpectedly.
Using
NSLog(@"%@", john);
I got the same result just after allocating and just before releasing, namely: "<Surroundings: 0x307180>"
-Mark
NSLog(@"%@", john);
I got the same result just after allocating and just before releasing, namely: "<Surroundings: 0x307180>"
-Mark
I think ThemsAllTook is probably on the money here -- run it through the debugger with "Guard Malloc" turned on.
Okay, cheers.
Guard Malloc pointed out an error in another function and getting rid of the [super dealloc] line in there seemed to fix things.
I can honestly say I don't understand at all but, er, at least it works?
Heh, thakns for all of your help,
Mark =)
Guard Malloc pointed out an error in another function and getting rid of the [super dealloc] line in there seemed to fix things.
I can honestly say I don't understand at all but, er, at least it works?
Heh, thakns for all of your help,
Mark =)
You should proably keep the [super dealloc] in your dealloc...
Were you calling dealloc from a method other than dealloc?
I wasn't, no. Although, now that I think about it I might have been calling [super dealloc] in two different subclasses of NSObject which would presumable have about the same effect.
I'm going to reread one of the books I have with memory management in mind, so cheers for all your help, but don't worry about it any more; I'll try to either figure it all out or be able to post something more specific.
Thanks again,
Mark
I'm going to reread one of the books I have with memory management in mind, so cheers for all your help, but don't worry about it any more; I'll try to either figure it all out or be able to post something more specific.
Thanks again,
Mark
A classic is to call [super dealloc] as the first line of your dealloc method. Try putting it last.
Quote:A classic is to call [super dealloc] as the first line of your dealloc method. Try putting it last.
Aaah, thank you.
That and making it so I only have a dealloc method in one of my files seems to have fixed it. However, it seems to do some strange things (ie. sometimes work, sometimes not, without any code changes) so we'll see what happens

-Mark

