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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:49:59+00:00 2026-06-08T20:49:59+00:00

I am trying to solve a larger problem and I am tipping on the

  • 0

I am trying to solve a larger problem and I am tipping on the fact that ARC apparently is releasing the view to my NSViewController too early. I think 🙂 So I created a simple app to reconstruct the situation.

I have a simple ARC Cocoa application. In the Window of the MainMenu.xib I hook up a Custom View to a @property (strong) IBOutlet NSView *theView; which is declared in the AppDelegate.h

In the AppDelegate.m I synthesize the property and then call the following:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    TestViewController *tvc =  [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
    [_theView addSubview:[tvc view]];
}  

The TestViewControllergets displayed in the Custom View – no problem. It contains one NSButton. It is hooked up to a method called -(IBAction)btnPressed:(id)sender and one NSTextView which is also hooked up as an IBOutlet.

In the TestViewController.h I declare:

@property (nonatomic, strong) IBOutlet NSTextField *textField;
@property (nonatomic, strong) NSString *theString;

-(IBAction)btnPressed:(id)sender;

In the TestViewController.m I then do

@synthesize theString = _theString;
@synthesize textField = _textField;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Initialization code here.
        _theString = @"Hello World";
    }

    return self;
}

-(IBAction)btnPressed:(id)sender
{
    [_textField setStringValue:_theString];
}

When I run the app and press the button it crashes. If I check it for zombies I receive the following:

#   Address Category    Event Type  RefCt   Timestamp   Size    Responsible Library Responsible Caller
0   0x7f97a3047560  TestViewController  Malloc  1   00:00.652.631   128 TestARC -[AppDelegate applicationDidFinishLaunching:]
1   0x7f97a3047560  TestViewController  Retain  2   00:00.653.088   0   TestARC -[TestViewController initWithNibName:bundle:]
2   0x7f97a3047560  TestViewController  Release 1   00:00.653.089   0   TestARC -[TestViewController initWithNibName:bundle:]
3   0x7f97a3047560  TestViewController  Retain  2   00:00.653.912   0   AppKit  -[NSNib instantiateNibWithOwner:topLevelObjects:]
4   0x7f97a3047560  TestViewController  Release 1   00:00.658.831   0   AppKit  -[NSNib instantiateNibWithOwner:topLevelObjects:]
5   0x7f97a3047560  TestViewController  Release 0   00:00.662.377   0   Foundation  -[NSNotificationCenter postNotificationName:object:userInfo:]
6   0x7f97a3047560  TestViewController  Zombie  -1  00:01.951.377   0   AppKit  -[NSApplication sendAction:to:from:]

What am I doing wrong?
Thanks

  • 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-08T20:50:01+00:00Added an answer on June 8, 2026 at 8:50 pm

    Add a property to hold the view controller. Your controller currently has nothing to keep it alive past the end of the method that allocates it.

    Add:

    @property (strong) TestViewController *tvc;
    

    Modify:

    self.tvc =  [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
    

    (I’m curious…what do you see as the point of creating a view controller if all you want is the view it contains?)


    Concerning the general approach, it seems that this is more properly behavior that should be implemented using a container view controller. That mechanism allows multiple view controllers to share the screen in an organized way.

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

Sidebar

Related Questions

I'm trying to solve the following problem in Redis. I have a list that
I am trying to solve this problem http://www.spoj.pl/problems/PEBBMOV/ . I think I have the
I've got a problem in a C++ program that I can't solve. I'm trying
I have a math problem that I solve by trial and error (I think
I have a problem that I have been trying to solve for a couple
Trying to solve a problem with templatetags. I have two templatetags: @register.inclusion_tag('directory/_alphabet.html') def alphabet_list(names):
Trying to solve this problem . I would like to learn how the bootstrapper
I'm trying to solve a codechef beginner problem - Enormous Input Test . My
I am trying to solve the following problem with Puppet: I have multiple nodes.
I'm trying to solve a gitignore problem on a large directory structure, but to

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.