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

  • Home
  • SEARCH
  • 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 643791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:19:16+00:00 2026-05-13T21:19:16+00:00

I am currently working through the famous Cocoa Programming for OSX by Aaron Hillegaas.

  • 0

I am currently working through the famous “Cocoa Programming for OSX” by Aaron Hillegaas.

In Chapter 12 he wants me to create an about window using

[BOOL] successful = [NSBundle loadNibNamed:@"About" owner:self];

which, by itself, works perfectly well. However, I am using the garbage collector and since I do not retain a pointer to that about window, it is garbage collected and thus disappears after a second or two. It works perfectly well if garbage collection is disabled.

Is there a way to create a window without holding a pointer to it and without having it eaten by the garbage collector?

  • 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-13T21:19:17+00:00Added an answer on May 13, 2026 at 9:19 pm

    You can retain the window with CFRetain, or use NSGarbageCollector‘s disableCollectorForPointer:. However, you can easily introduce a memory leak. Make sure whichever action you use to close the window also releases the window.

    If the sender passed to the close action inherits from NSView, it will have a window property that you can use to get a pointer to the window.

    However, this is not how Cocoa is designed to work. In Chapter 12 of Hillegaas’ book, he has this to say:

    When sent showWindow: for the first time, the NSWindowController automatically loads the nib file and moves the window on screen and to the front. The nib file is loaded only once. When the user closes the [window], it is moved off screen but is not deallocated. The next time the user asks for the [window], it is simply moved on screen.

    If you deallocate the About window, your app will either crash or appear not to respond the second time someone opens it.

    Edit: An alternative (but one that doesn’t give you practice in loading nibs) is to add the About window an an NSWindowController to the main nib (make sure you uncheck the About window’s “Visible At Launch” attribute). This makes a mess of Main.nib, but can be done entirely in Interface Builder. Connect:

    • the About controller’s window outlet to the About window
    • the About controller’s showWindow: action to the About menu item
    • if you’ve your own close button in the About window, connect it to the window’s performClose: action.

    As for how advisable this course is, Apple has this to say:

    A very simple application might be able to store all of its user interface components in a single nib file, but for most applications, it is better to distribute components across multiple nib files. Creating smaller nib files lets you load only those portions of your interface that you need immediately. Smaller nib files results in better performance for your application. They also make it easier to debug any problems you might encounter, since there are fewer places to look for problems.

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

Sidebar

Related Questions

I'm currently working through the excercises in 'The C Programming Language'. Here's one of
I am currently working on a simple web application through Google App engine using
I am currently working through SICP using Guile as my primary language for the
I'm currently working through O'Reilly's Programming PHP and have come across this table titled
I'm working through a jQuery book and am currently on the chapter of table
I am currently working through SICP's section on Logic Programming, but I got stuck
I'm currently working through Thinking in C++, and chapter 9, exercise 15 gives instructions
I'm currently working through Professional Plone 4 Development while using the unified installer for
I'm working through SICP. Currently, in the first chapter, I'm having problems getting Racket
I'm currently working through an assignment that deals with Big-O and running times. I

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.