Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-30-2010, 04:01 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 67
sajjadzare is on a distinguished road
Default Release

if i declare NSString *a=[[NSString alloc]...]
Does it neccessary to relese a

if yes
Why ?
Where should i relese it ?
if i don't relese it what happen ?
sajjadzare is offline   Reply With Quote
Old 06-30-2010, 04:13 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by sajjadzare View Post
if i declare NSString *a=[[NSString alloc]...]
Does it neccessary to relese a

if yes
Why ?
Where should i relese it ?
if i don't relese it what happen ?
Yes, "a" must be released because "alloc" causes memory to be allocated to contain the NSString object. If you do not ever release it, then that memory cannot be used for anything else. And if you do this over and over again in your app, you will allocate more and more memory, until you run out of memory and your app stops working.

Where should you release it? Anywhere in the code that did the alloc after the last point where that code needs to access it. This does not cover other objects that may have done a retain on their own, such as when you add the NSString to something. If you do that, then the other object has the responsibility to do another release when it is done. You can safely do a release without worrying about when that other object is going to be done with it.

Robert Scott
Ypsilanti, Michigan
RLScott is offline   Reply With Quote
Old 07-01-2010, 12:07 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 67
sajjadzare is on a distinguished road
Default

when should i use [self. ...=nil] ?
sajjadzare is offline   Reply With Quote
Old 07-01-2010, 12:30 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 342
flamingliquid is on a distinguished road
Default

When you have a property that retains.
__________________
17 year old nerd.
Send me a PM. Maybe I can help.
flamingliquid is offline   Reply With Quote
Old 07-01-2010, 12:49 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 67
sajjadzare is on a distinguished road
Default

Quote:
Originally Posted by flamingliquid View Post
When you have a property that retains.
for property both of [self. ...=nil] and relese .., are neccessary ?
sajjadzare is offline   Reply With Quote
Old 07-07-2010, 12:10 PM   #6 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by sajjadzare View Post
for property both of [self. ...=nil] and relese .., are neccessary ?
No, self.XXX =nil does release XXX, but it also sets the instance variable XXX equal to nil. In most cases a simple "release" is enough, because the instance variable, or temporary variable, or whatever, is never going to be referenced again (as in a dealloc method). But if the scenario has the possibility that you might try to access the variable after it has been released, then use self.XXX = nil, so that you will not try to access memory that does not belong to you anymore.

Robert Scott
Ypsilanti, Michigan
RLScott is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 328
7 members and 321 guests
anothermine, Chickenrig, Domele, givensur, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:24 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0