Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8692263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:16:59+00:00 2026-06-13T00:16:59+00:00

Say I have a menu button called ‘Create window’ that creates a new window:

  • 0

Say I have a menu button called ‘Create window’ that creates a new window:

MyWindowClass * window = [MyWindowClass new];

In order to retain it, I add it to a mutable array (declared and synthesised as _articleArray = [NSMutableArray new];)

[_articleArray addObject:window]

This works great. If I include:

NSLog(@"Windows in mem: %lu",_articleArray.count);

The number increments each time that I click the button and another window appears on the screen.

Now, if I attach a selector to this ‘create window’ function to identify when the window closes:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowClosed:) name:NSWindowWillCloseNotification object:window];

This creates an error:

-(void) windowClosed:(NSNotification*)notification {
    [_articleArray removeObject:[notification object]];
    NSLog(@"Windows in mem: %lu",_articleArray.count);

The NSLog decrements when I close a window as expected, but as soon as the function ends, it throws an EXC_BAD_ACCESS error (code 13, address=0,0)

0x7fff97878710:  movq   24(%rax), %rax

I am very confused. The number decrements, so I can only think that the function is working. So what is happening here?

EDIT: (lldb) thread backtrace

* thread #1: tid = 0x1c07, 0x00007fff97878710 libobjc.A.dylib`objc_msgSend_vtable13 + 16, stop reason = EXC_BAD_ACCESS (code=13, address=0x0)
frame #0: 0x00007fff97878710 libobjc.A.dylib`objc_msgSend_vtable13 + 16
frame #1: 0x00007fff97571503 Foundation`__NSFireTimer + 80
frame #2: 0x00007fff993a6da4 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
frame #3: 0x00007fff993a68bd CoreFoundation`__CFRunLoopDoTimer + 557
frame #4: 0x00007fff9938c099 CoreFoundation`__CFRunLoopRun + 1513
frame #5: 0x00007fff9938b6b2 CoreFoundation`CFRunLoopRunSpecific + 290
frame #6: 0x00007fff8df260a4 HIToolbox`RunCurrentEventLoopInMode + 209
frame #7: 0x00007fff8df25e42 HIToolbox`ReceiveNextEventCommon + 356
frame #8: 0x00007fff8df25cd3 HIToolbox`BlockUntilNextEventMatchingListInMode + 62
frame #9: 0x00007fff92ce3613 AppKit`_DPSNextEvent + 685
frame #10: 0x00007fff92ce2ed2 AppKit`-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
frame #11: 0x00007fff92cda283 AppKit`-[NSApplication run] + 517
frame #12: 0x00007fff92c7ecb6 AppKit`NSApplicationMain + 869
frame #13: 0x0000000100006942 myApp`main + 34 at main.m:13
frame #14: 0x00007fff9094f7e1 libdyld.dylib`start + 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:17:00+00:00Added an answer on June 13, 2026 at 12:17 am

    This answer has been moved from the comments in the question at the request of the OP

    You need to ensure that you remove your NSWindowWillCloseNotification observer before the window is destroyed:

    -(void) windowClosed:(NSNotification*)notification {
        NSWindow *window = [notification object];
        [[NotificationCenter defaultCenter] removeObserver:self
                                                      name:NSWindowWillCloseNotification
                                                    object:window];
        [_articleArray removeObject:window];
        NSLog(@"Windows in mem: %lu",_articleArray.count);
        ...
    

    And also ensure that the window has its isReleasedWhenClosed property set to YES so that it cleans-up after itself when closed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a menu item and a button that do the same task.
There is a new concept in Android: http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html But it isn't clear fro me.
I read http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html but have some issues. For pre-honeycomb I want a custom title,
Let me explain what I mean : Let's say we have a menu with
Say I have a bog-standard Win32 popup menu, and it's taller than the screen.
Say I have a form_for with a select menu to assign a User on
Is it possible to have a collapsible menu in a fragment, say for example...
I have an NSMenu (let's say the Main Menu), with lots of NSMenu s
I have navigation menu using images, I want that if the user click a
So I have an accordion menu to display results and a Show All button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.