Re: Beginner Question Re: Memory Management
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