• 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: Beginner Question Re: Memory Management
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Beginner Question Re: Memory Management


  • Subject: Re: Beginner Question Re: Memory Management
  • From: Quincey Morris <email@hidden>
  • Date: Mon, 22 Jun 2009 22:29:44 -0700

On Jun 22, 2009, at 21:31, WT wrote:

So, to all beginners out there, whenever you define a property, remember always to refer to it, in its own class, by self.property - at least when setting its value. It may be ok (depending on what you're doing) to refer to it simply by property when *getting* its value, but if the property is backed by an instance variable that is an object (rather than a scalar type), it's *essential* that you refer to it by prepending self when *setting* its value, or you'll not be doing the memory management that you think you're doing.

I understand what you're trying to say here, but I'd urge you *never* to describe it in these terms.


You say, explicitly, that it's a question of use the the correct way (out of a choice of 2 ways) to refer to a property. But that's not so. There's *one* way to refer to a property, and *one* way to refer to an instance variable. The fact that they may have similar names is purely an accident. (Well, not an accident, generally, but a convenience.)

I'd say it's really, really, really important for beginners to realize that properties and the instance variables that back them are different, syntactically and semantically. Outside a class implementation, the property is the only thing that's available (or should be, since making instance variables public is usually a Bad Idea), so clients of the class don't have to think about it. Inside a class implementation, however, you need to decide *every time you refer to a value* whether you mean the property value or the instance variable value. You need to decide that even when you *know* that the two values are currently the same, because in a future piece of the implementation you may break the congruence, but you don't want to break the existing code if you can help it.

It's not even about memory management. There's often memory management involved when using a property's accessors, but there may also be memory management involved when dealing with an instance variable in other contexts.

FWIW.


_______________________________________________

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


  • Follow-Ups:
    • Re: Beginner Question Re: Memory Management
      • From: WT <email@hidden>
    • Re: Beginner Question Re: Memory Management
      • From: Eric Hermanson <email@hidden>
References: 
 >Beginner Question Re: Memory Management (From: Daniel Torrey <email@hidden>)
 >Re: Beginner Question Re: Memory Management (From: Graham Cox <email@hidden>)
 >Re: Beginner Question Re: Memory Management (From: WT <email@hidden>)

  • Prev by Date: Re: Beginner Question Re: Memory Management
  • Next by Date: Re: Problem with NSValueTransformer, NSTableView and NSAttributedString
  • Previous by thread: Re: Beginner Question Re: Memory Management
  • Next by thread: Re: Beginner Question Re: Memory Management
  • Index(es):
    • Date
    • Thread