Re: object ownership question
Re: object ownership question
- Subject: Re: object ownership question
- From: Peter Ammon <email@hidden>
- Date: Tue, 03 Jul 2001 09:39:15 -0700
on 7/2/01 11:37 PM, Bob Savage at email@hidden wrote:
>
Peter Ammon wrote:
>
>
> after your code is done and control
>
> is returned to the main event loop, it will be released.
>
>
I am still somewhat confused about two things here:
>
>
1. What do you mean by "return"? Do you mean any method that returns, or do
>
you mean backing completely out of a nest of method calls, until you don't
>
have control over the code anymore? I would assume the latter <-- GUESS
You're right. Control usually transfers to your own code in one of several
standard methods: init, awakeFromNib, drawRect:, keyDown:, etc. From there,
it often branches into other methods. You can think of all autoreleased
objects being sent a release message just after each top level method, where
you first gained control, returns.
>
>
This is important because I want to know whether it is okay to do this:
>
>
id anOBJ = [supplier gimmeAnOBJ]; // do I need a retain here?
>
theNUM = [anotherOBJ returnSomething];
>
[anOBJ doSomething];
>
>
Does the returnSomething method call potentially invalidate the non-retained
>
instance anOBJ?
>
Not at all; that code is fine.
>
2. Another question about memory: What happens if I forget to release some
>
object before the application terminates? Is that memory still occupied
>
until a reboot, or will it get freed automatically at the end of the
>
process?
It gets freed (or at least is supposed to) when the process exits.
-Peter