Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  Variables Inside Cocoa Objects
Subject:   Setter example
Date:   2002-04-13 17:22:14
From:   shiny
Hi,


Thanks for your timely article on AppleScript and Cocoa. I found your article very informative and enjoyable.


Just a minor point. Your setter example causes some problems such as memory leak. Your code


mystring = str;


should've been


[mystring autorelease]; or [mystring release];
mystring = [str copy]; or mystring = [str retain];


Thanks again for your article. I'm looking forward to reading your next one.


shin

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Re: Setter example
    2002-04-14 10:06:35  bdominy [View]

    Hi Shin,

    You are quite correct that one of your suggested means of releasing the existing mystring should have been used when making the new assignment to avoid memory leaks. I can only claim that I was trying to use the minimum amount of code to keep all of the concepts clear and I didn't want to introduce the issues concerning memory management and Objective-C. But, for completeness you are absolute correct and I will add this to future examples.

    Brad