• 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: XCode not releasing nsstring
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XCode not releasing nsstring


  • Subject: Re: XCode not releasing nsstring
  • From: Oleg Svirgstin <email@hidden>
  • Date: Wed, 12 Nov 2003 14:20:47 +0300

Hi all,

As the other people said, [x release] does not change the address that "x"
points to, just invalidates the object pointed by "x" if the "x"'s retention
count reaches zero.

I normally define this macro
#define RELEASE_IF(a) if(a)[a release];a=nil

Notwithstanding some evident limitations in it (you see, I don't check for
cases with retention count > 1, so I use that macro with the open eyes),
this macro proves to be very useful.

There is an idea... I am not sure about filing an enhancement request on it,
since I am not quite sure whether it would be good or bad, but if some basic
object (NSObject, or even "lower") would take care of automatically changing
its pointer numeric value when de-allocated, it would have saved some people
some hair.

It could be some specific value or even just plain "zero".

It could be smth like "releaseAndClean" and "autoreleaseAndClean". I would
NOT like making standard "release" and "autorelease" lose extra cycles.

Normally it is quite enough to never forget that
- one should never assume an instance is equal to "nil" before it was
assigned nil
- neither release, nor autorelease affect the instance variable numeric
value
- sending a message to nil does not crash, in most cases just nothing
happens. Setting an object variable to nil makes sense only if we check it
before use. Sending a message to an invalid object does crash.
(Could somebody tell that all in better English?)

So, the answer should read "Cocoa/Objective-C (not XCode) does release the
nsstrings (and all the other objects around) when appropriate".

Regards
Oleg



> From: James Spencer <email@hidden>
> Date: Tue, 11 Nov 2003 21:12:06 -0600
> To: Cocoa Posting <email@hidden>
> Subject: Re: XCode not releasing nsstring
>
> On Nov 11, 2003, at 7:20 PM, Justin Lundy wrote:
>
>> [releaseTest release];
>>
>> if (releaseTest != nil) NSLog(@"C: releaseTest NOT nil.");
>> if (releaseTest == nil) NSLog(@"C: releaseTest nil.");
>>
>> and guess what the log said?
>>
>> A: releaseTest nil.
>> B: releaseTest NOT nil.
>> C: releaseTest NOT nil.
>>
>> Call me crazy, but shouldn't the last one say "C: releaseTest nil."?
>>
>
> Your test doesn't test whether the object has been released; it tests
> whether the variable release test is nil. It's not; it still contains
> the pointer to the old (no longer valid) NSString. Try sending a
> message to the released object and you should get an error back.
>
> James P. Spencer
> Rochester, MN
>
> email@hidden
>
> "Badges?? We don't need no stinkin badges!"
> _______________________________________________
> 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.
_______________________________________________
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.

References: 
 >Re: XCode not releasing nsstring (From: James Spencer <email@hidden>)

  • Prev by Date: Re: Matching Postal Addresses
  • Next by Date: WebView tooltips
  • Previous by thread: Re: XCode not releasing nsstring
  • Next by thread: Re: XCode not releasing nsstring
  • Index(es):
    • Date
    • Thread