• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSWindow Subclass close/dealloc question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSWindow Subclass close/dealloc question


  • Subject: Re: NSWindow Subclass close/dealloc question
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 02 Apr 2015 13:16:45 -0500

On Apr 2, 2015, at 11:53 AM, Dave <email@hidden> wrote:

> On 2 Apr 2015, at 17:09, Ken Thomases <email@hidden> wrote:
>>
>> On Apr 2, 2015, at 10:56 AM, Dave <email@hidden> wrote:
>>
>>> I’m getting a crash in dealloc in an NSWindow Subclass.
>>
>>> If I run this, then I get a crash when the autorelease pool is drained. However, if I take out the line:
>>>
>>> [super close];
>>>
>>> in my close method, all works fine.
>>>
>>> Is this expected?
>>
>> If you have a window which is not being controlled by a window controller and whose releasedWhenClosed property is true (default for NSWindow), then it will be released when it is closed (unsurprisingly).  Therefore, you should not release it again yourself or you will over-release it and cause a crash (or worse).
>>
>> The easiest thing to do is to always turn off releasedWhenClosed so that window objects obey normal memory management conventions.
>>
>> Regards,
>> Ken
>
> Hi thanks for this, Yes, releasedWhenClosed because there it used a lot of memory. I guess I could just test of releasedWhenClosed == YES and NOT call [super close]; in my subclasses close method?

No, then the window will be uncloseable.  What needs to be different depending on that property is whether you call -release, not whether you pass the -close call up to super.  If you're using ARC, you don't get to control whether you call release.  Therefore, you need to set releasedWhenClosed to NO.

If you're experiencing leaks when releasedWhenClosed is false, then that's a separate bug in your code, which you need to fix.

Regards,
Ken


_______________________________________________

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


  • Follow-Ups:
    • Re: NSWindow Subclass close/dealloc question
      • From: Dave <email@hidden>
References: 
 >NSWindow Subclass close/dealloc question (From: Dave <email@hidden>)
 >Re: NSWindow Subclass close/dealloc question (From: Ken Thomases <email@hidden>)
 >Re: NSWindow Subclass close/dealloc question (From: Dave <email@hidden>)

  • Prev by Date: Re: Swift: How to determine if a Character represents whitespace?
  • Next by Date: Re: NSWindow Subclass close/dealloc question
  • Previous by thread: Re: NSWindow Subclass close/dealloc question
  • Next by thread: Re: NSWindow Subclass close/dealloc question
  • Index(es):
    • Date
    • Thread