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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:55:38+00:00 2026-05-15T08:55:38+00:00

At various points during my application’s workflow, I need so show a view. That

  • 0

At various points during my application’s workflow, I need so show a view. That view is quite memory intensive, so I want it to be deallocated when it gets discarded by the user. So, I wrote the following code:

- (MyView *)myView {
    if (myView != nil)
        return myView;

    myView = [[UIView alloc] initWithFrame:CGRectZero]; // allocate memory if necessary.
    // further init here

    return myView;
}

- (void)discardView {
    [myView discard];   // the discard methods puts the view offscreen.
    [myView release];   // free memory!
}

- (void)showView {
    view = [self myView];
    // more code that puts the view onscreen.
}

Unfortunately, this methods only works the first time. Subsequent requests to put the view onscreen result in "message sent to deallocated instance" errors. Apparently, a deallocated instance isn’t the same thing as nil. I thought about putting an additional line after [myView release] that reads myView = nil. However, that could result in errors (any calls to myView after that line would probably yield errors).

So, how can I solve this problem?

  • 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-15T08:55:39+00:00Added an answer on May 15, 2026 at 8:55 am

    Setting myView to nil is the correct thing to do here. Not doing so is what’s yielding errors, because it undetectably refers to a deallocated object. Your code tests for nil to see if it needs to create a new view, so you should set the variable appropriately.

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

Sidebar

Related Questions

I want users to receive 'points' for completing various tasks in my application -
I have a class that has an Action<string> called DisplayData ; In various points
Let's say in various points in my application, I create and fire off a
In my application I have various styles and templates that are used in several
My application crashes at various points while running, and result with the following error,
I currently have an application which will drop pins onto various points of interest
You are given a list of distances between various points on a single line.
I'm printing out the stack trace in my app at various points to debug
Various sites on the internet claims that Safari cache on iPhone 2.2 is 25k
I have a Java application that needs to collect and report a large number

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.