• 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: Michael Ash <email@hidden>
  • Date: Tue, 23 Jun 2009 10:16:11 -0400

On Tue, Jun 23, 2009 at 12:31 AM, WT<email@hidden> wrote:
> What the heck???
>
> So, after I scratched my head silly for several minutes, it suddenly came to
> me. If I'm going to use a property, I *must* refer to it as object.property
> rather than simply as property. In the specific example I had, I should not
> have replaced all those repeated chunks of code with
>
> textFieldPreviousContent = textField.text;
>
> but with
>
> self.textFieldPreviousContent = textField.text;
>
> Using
>
> textFieldPreviousContent = textField.text;
>
> meant that I was bypassing the very memory management I thought I was
> getting for free by turning textFieldPreviousContent into a property. Of
> course, my mistake implied that a) I was leaking the string pointed to by
> textFieldPreviousContent and b) I was not retaining the string returned by
> textField.text. And since that string is returned to me auto-released,
> textFieldPreviousContent ended up pointing to a memory location that was no
> longer valid by the time I used its contents. No wonder my app crashed.

Stuff like this is why I believe this silly dot syntax thing should be
avoided completely. If you had written [self
setTextFieldPreviousContent:[textField text]], not only would you have
avoided the mysterious crash, but it's *much* clearer exactly what's
going on. Using dot syntax instead of brackets only saves you maybe
four characters of typing and costs you dearly in terms of clarity.

Mike
_______________________________________________

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

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: Opinion on managed memory and garbage collection
  • Next by Date: Re: Beginner Question Re: Memory Management
  • Previous by thread: Re: Beginner Question Re: Memory Management
  • Next by thread: Re: Beginner Question Re: Memory Management
  • Index(es):
    • Date
    • Thread