Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: crash on custom NSWindow subclass dealloc



On Dec 19, 2007 1:19 AM, Wesley Smith <email@hidden> wrote:
> I have a custom subclass of NSWindow that I've defined a dealloc
> method for as so:
>
> - (void)dealloc
> {
>         [ogl_view release];
>         NSZoneFree([self zone], [self zone]);
>         [super dealloc];
> }

NSZoneFree line is incorrect for a few reasons (one is your object
doesn't own the zone it was allocated from so it shouldn't attempt to
free that zone).

In dealloc you are responsible for releasing any objects your object
maintains a retain on and/or any memory your object allocated and
owns. You are not supposed free memory of your own object in dealloc.
Your object was sent a dealloc message by the runtime because the
runtime is about to destroy the object and the runtime wants you clean
up anything your object owns.

Even C++ you don't free the object itself in the destructor.

-Shawn
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >crash on custom NSWindow subclass dealloc (From: "Wesley Smith" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.