Autopool question
Autopool question
- Subject: Autopool question
- From: Lars Hoss <email@hidden>
- Date: Tue, 7 Aug 2001 16:26:19 +0200
Hi!
I have a little question about autorelease pools and how they
free objects.
Let's assume I have the following method in the class Foo:
-(MyObject *)object
{
// create a MyObject instance somehow ...
// ref counter on myObject is now 1
MyObject *myObject = ...
[myObject autorelease];
return myObject;
}
Then I have a method in the class Foe:
-(void)doSomethingWithObject
{
Foo *fooInstance = [[Foo alloc] init];
myObject = [fooInstance object]; // myObject is a class variable
[myObject retain]; // ref counter now is 2
[fooInstance release];
}
The class Foe needs the instance foo for a longer time.
Since I put myObject into the autorelease pool wouldn't
it be freed after two event cycles?
Thanks for your help in advance.
Yours,
Lars
--
mailto:email@hidden
icq: 19903263