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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:53:15+00:00 2026-05-22T21:53:15+00:00

i have some trouble writing a method in Objective-C to make an object nil.

  • 0

i have some trouble writing a method in Objective-C to make an object nil. Here is some example :

@interface testA : NSObject
{
     NSString *a;
}

@property (nonatomic, retain) NSString *a;

+(testA*)initWithA:(NSString *)aString;

-(void)displayA;
-(void)nillify;
@end

@implementation testA
@synthesize a;
+(testA*)initWithA:(NSString *)aString{
    testA *tst=[[testA alloc] init];
    tst.a=aString;
    return [tst autorelease];
}
-(void)displayA{
    NSLog(@"%@",self.a);    
}
-(void)nillify{
    self=nil;
}
- (void)dealloc {
    [a release];
    [super dealloc];
}
@end

int main(int argc, char **argv){
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    testA *test=[testA initWithA:@"some test"];
    [test displayA];
    test=nil;
    //[test nillify];

    NSLog(@"after setting to nil");

    [test displayA];
    [pool release];
    return 0;
}

Apparently , when I set test object to nil and then call some method on it nothing happens , but if i call nillify instead of directly setting it to nil , displayA method works normally like test object is still there. Is there a workaround for nillify method to function properly ?

Your help is much appreciated !

  • 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-22T21:53:16+00:00Added an answer on May 22, 2026 at 9:53 pm

    You can’t actually do something like this, because setting ‘self’ to nil only has any effect within the scope of that method (in your case, ‘nilify’). You don’t have any actual way to effect the values of pointers located on other parts of the stack or in random places in the heap, for example.

    Basically any code that holds a reference to some object is responsible for maintaining and clearing those references itself. If you have some use case where random sections of code may need references to “live” objects of some kind, but where you’d want those object references to go away in response to some external event (maybe a user tracking system or something), you could do something with notifications, but the various modules tracking those “live” objects would still be responsible for listening for notifications and cleaning up references when they received them.

    The ‘nilify’ thing, however, can’t possibly work.

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

Sidebar

Related Questions

I'm having some trouble with a generic method I'm writing. It has the following
I have some trouble with regex and php here: <span style=color: blue>word1</span> word by
I'm migrating to Nhibernate 2.0 GA but have some trouble with setting cache expirations
I am developing a small windows app, but have some trouble deciding whether to
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I am having some trouble with the Google Maps API . I have an
I have created some rounded navigation tabs using CSS and am having trouble when
I'm writing an Android app. I have a main method, which creates and runs
I have some trouble for choosing the right type of exception to throw when
I am have some trouble specifying a custom icon in my WPF applicaion. 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.