• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re:Simple dealloc question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:Simple dealloc question


  • Subject: Re:Simple dealloc question
  • From: <email@hidden>
  • Date: Mon, 15 Oct 2007 14:17:06 +0530
  • Thread-topic: Re:Simple dealloc question

Found the following code in an example (track is a pointer to a Track
object)

- (void)dealloc

{

[track release], track = nil;

[super dealloc];

}



What is the point of having track = nil? Wouldn't the following code be
enough?

- (void)dealloc

{

[track release];

[super dealloc];

}



Bob

------------------------------------------------------------------------
----------------------------

Hi Bob,

Consider the following code snippet

my_obj = [ [ NSMutableArray alloc] init ];
[ my_obj release ];  // freeing the object my_obj
[ my_obj count];     // sending message count to freed object

In the above snippet we are freeing an object and then sending a message
to it.
This will cause a crash.

To prevent such a crash many programmers after releasing an object set
its pointer to nil.

[ my_obj release ];  // freeing the object my_obj
my_obj = nil ;


Best Regards,
Amrit.





The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Simple dealloc question
  • Next by Date: Re: Simple dealloc question
  • Previous by thread: Re: Simple dealloc question
  • Next by thread: Re: Simple dealloc question
  • Index(es):
    • Date
    • Thread