• 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: self release
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: self release


  • Subject: Re: self release
  • From: David Remahl <email@hidden>
  • Date: Mon, 12 May 2003 19:44:59 +0200

Yes, that is definitely a bad idea, since it violates basic memory management principles. What you retain / alloc you must release!

Something like this, is better:

MyWorkingBee *bee = [MyWorkingBee workingBeeWithWorkDesc:info];
[bee runInBackground];

If the code you suggested is used, then a casual reader of your code would see the alloc / init and react to the fact that there is no release matched to it. He might add it after runInBackground, and that would cause the application to crash when the background process then uses a method on itself (or sends itself autorelease).

/ Rgds, David

On Monday, May 12, 2003, at 07:26 PM, Wolfgang Ante wrote:

Is it OK to "[self release]"?

The only time I've had occasion to do so was in an -init method, where initialization failed and I needed to avoid leaking memory. Other than such a situation, sending -release to self is very >> unusual.

Yes, I have noticed that!

Well, my idea is to have a quite independent object that does things in the background (and is kept alive either with timers or with threads) and when it is finished it kills itself.

Like writing something like...

[[[MyWorkingBee alloc] initWithWorkDesc:info] runInBackground];

...and then not caring about it any more.

Bad idea?

Bye, Wolfgang :-)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: self release
      • From: Wolfgang Ante <email@hidden>
References: 
 >Re: self release (From: Wolfgang Ante <email@hidden>)

  • Prev by Date: Re: Absolute Beginner
  • Next by Date: Re: self release
  • Previous by thread: Re: self release
  • Next by thread: Re: self release
  • Index(es):
    • Date
    • Thread