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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:06:34+00:00 2026-05-14T05:06:34+00:00

I have several objects in my app that can become nil at some point

  • 0

I have several objects in my app that can become nil at some point and I have methods that in theory are used to put these objects to nil.

But, if I try to put to nil an object that does not exist, the app will crash.

for example…

[object1 release];
object1 = nil;

//… and after that

[object1 removeFromSuperview]; // this will crash

Then I thought, why not testing to see if the object exists before removing…

if (object1 != nil)
 [object1 removeFromSuperview]; 
// this will crash too, because object1 cannot be tested for nil because it does not exist

How can I check if the object exists before testing if it is nil?
something as

if (object1 exists( {
  if(object1 != nil))
    [object1 removeFromSuperview)
}

is this possible?

I ADDED THIS TO CLARIFY…

what I mean is this: imagine I have object1 declared on the header and initialized on the code. So, it exists and points to a valid reference. At some point, the object may be released, so the reference still points to an object but the object was freed. Even if I put the object to nil after releasing, I cannot do anything with it.

The problem is this: I have some methods that are asynchronous. One of them scans for some objects and remove them if they are found. I must check if the object exists and the reference points to a valid object before releasing it again. This is the point: how do I test if the object exists and its reference points to a valid existent object before releasing it again, to void releasing again an object that is already released and crash the app.

  • 1 1 Answer
  • 2 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-14T05:06:34+00:00Added an answer on May 14, 2026 at 5:06 am

    In short, your question of determining if the pointer is still valid is going down the wrong path.

    After you release an object, you must immediately set its value to null so that you no longer control it. If two methods are running asynchronously accessing the same object, they must be synchronized at that point so that releasing and setting to null happens at the same time in one thread before the other has a chance to interrupt.

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

Sidebar

Related Questions

I have users that have several objects and can upload images for those objects.
I have several methods that populate a SQLCommand objects parameter collection from an object
I have a mutable array that is retained and storing several objects. At some
I'm trying to put together a form_tag that edits several Shift objects. I have
In the app I'm developing I'm creating several objects that each have the following
I have an iPhone app that used to use an array of several thousand
I have a class that is called regularly by several objects. I would like
I have an ASP.NET web app that places several string data into an object
I'm writing an app (in iOS 5 using ARC!) that presents several hundred objects
I am making an app that will make several HttpWebRequest objects and downloading my

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.