Re: showing window causes EXC_BAD_ACCESS
Re: showing window causes EXC_BAD_ACCESS
- Subject: Re: showing window causes EXC_BAD_ACCESS
- From: "Michael Ash" <email@hidden>
- Date: Sat, 27 Sep 2008 23:55:00 -0400
On Sat, Sep 27, 2008 at 4:44 PM, Uli Kusterer
<email@hidden> wrote:
> On 27.09.2008, at 22:13, Michael Ash wrote:
>>
>> But suddenly you're back to having to think about the global picture
>> of who owns objects, which is what Cocoa's memory management system is
>> supposed to avoid.
>>
>
>> Retains and releases should be balanced. This doesn't just means that
>> they should ultimately be equal in number, it also means that the same
>> entity should be doing both. "Release when closed" breaks the
>> fundamental memory management rules and, as a consequence, makes it
>> much more complicated to think about how the program works.
>
> You're misunderstanding the purpose of Cocoa's memory management system:
> It's not about not having to care who owns what, it's about not having to
> worry about shared ownership. There are many cases (threading and creation
> of objects come to mind) where ownership is handed from one object to the
> other.
It's just two different sides of the same coin. Why is it useful to be
able to ignore shared ownership? Because it turns memory management
from a global problem into a local problem. How does Cocoa make memory
management a local problem? By allowing us to easily deal with shared
ownership.
I did not mean to imply that ownership never gets passed from one
object to another. Only that when you balance a retain with a release,
the entity doing the release should be the same one doing the retain.
Anything other approach turns the problem back into a global one, and
makes life much more difficult.
> In this case, you specify in the NIB that you want your window to release
> itself, and you haven't written your outlet in a way that it retains the
> window. If you expect your window to not go away when closed, you're
> expecting too much.
Except that in every case I've seen of people getting bit by this, the
window was still being implicitly retained by the nib's File's Owner.
You should definitely *not* expect a top-level nib object to go away
until File's Owner releases it.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden