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 6026159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:24:20+00:00 2026-05-23T04:24:20+00:00

In an application (OS X 10.6.7) I have a NSWindowController subclass which is initialized

  • 0

In an application (OS X 10.6.7) I have a NSWindowController subclass which is initialized with -[NSWindowController initWithWindow:]—i.e., I have already created the window in code; I’m not loading it from a nib.

Normally, I refer to the window in my NSWindowController subclasses with [self window]. But in this case, every time I send [self window], the window gets retained, so I end up leaking quite a lot.

Is this intended behavior? For the moment I’ve worked around it by just storing the window in an instance variable in the init method and never sending [self window].

I am pretty sure this is not happening because NSWindowController is trying to load the window: -loadWindow does not retain the window and -isWindowLoaded returns YES:

(gdb) set $window = (id)[self window]
Current language:  auto; currently objective-c
(gdb) p (int)[$window retainCount]
$1 = 3
(gdb) p (BOOL)[self isWindowLoaded]
$2 = 1 '\001'
(gdb) call (void)[self loadWindow]
(gdb) p (int)[$window retainCount]
$3 = 3
(gdb) p (int)[[self window] retainCount]
$4 = 4
(gdb) p (int)[[self window] retainCount]
$5 = 5
  • 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-05-23T04:24:21+00:00Added an answer on May 23, 2026 at 4:24 am

    -[NSWindowController window] retaining the window is fine; the issue seems to be related to autorelease pools.

    window = [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 200, 200)
                                                   styleMask:NSTitledWindowMask
                                                     backing:NSBackingStoreBuffered
                                                       defer:NO];
    NSWindowController *controller = [[NSWindowController alloc] initWithWindow:window];
    [window setTitle:@"testing"];
    [window makeKeyAndOrderFront:nil];
    [window release];
    NSLog(@"[window retainCount]: %d", [window retainCount]);
    [controller window];
    [controller window];
    [controller window];
    NSLog(@"[window retainCount]: %d", [window retainCount]);
    
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [controller window];
    [controller window];
    [controller window];
    NSLog(@"[window retainCount]: %d", [window retainCount]);
    [pool drain];
    NSLog(@"[window retainCount]: %d", [window retainCount]);
    

    The output is:

    2011-06-12 19:26:52.337 window[5517:a0b] [window retainCount]: 1
    2011-06-12 19:26:52.339 window[5517:a0b] [window retainCount]: 4
    2011-06-12 19:26:52.340 window[5517:a0b] [window retainCount]: 7
    2011-06-12 19:26:52.340 window[5517:a0b] [window retainCount]: 4
    

    The problem was that I forgot to create a pool when doing Cocoa stuff in a Carbon event handler (InstallApplicationEventHandler). This matches the context of the thread I linked to.

    Ordinarily I see an exception when there’s no autorelease pool present, so I’m guessing there is simply a pool in place that never gets drained.

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

Sidebar

Related Questions

In my application I have a window which I popup with small messages on
I have Silverlight application that retrieves data from the database through a WCF Service.
i want to send email from my application,how can write code for send email
I have an application with an NSMenuItem that launches a separate window and I
I have created a WCF Data Service and using it in a web application
I have got a requirement from a client. They need three blogging web application
my application have a tabbarcontroller with 4 view Controllers. Its called here : self.window.rootViewController
Users of my application have the possibility of choosing some values from list. The
I have an application which have a system add button the navigation bar .on
I have a Windows Mobile Desktop Application that have some text fields which will

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.