• 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: [OBJC newbie] - Intance variable becomes 'invalid'
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OBJC newbie] - Intance variable becomes 'invalid'


  • Subject: Re: [OBJC newbie] - Intance variable becomes 'invalid'
  • From: Chas Spillar <email@hidden>
  • Date: Wed, 31 May 2006 11:59:43 -0700
  • Thread-topic: [OBJC newbie] - Intance variable becomes 'invalid'

In addition, the various factory methods that you can call on a class are
also not retained for you:

E.g.

NSString *mystring = [NSString string];

You need to retain this to use later...

[mystring retain];

In this case you can probably just go ahead use alloc and init:

NSString *mystring = [[NSString alloc] init];

Chas.


> From: Chas Spillar <email@hidden>
> Date: Wed, 31 May 2006 11:56:39 -0700
> To: Graham <email@hidden>
> Cc: Cocoa Dev List <email@hidden>, Chas Spillar
> <email@hidden>, Chas Spillar <email@hidden>
> Conversation: [OBJC newbie] - Intance variable becomes 'invalid'
> Subject: Re: [OBJC newbie] - Intance variable becomes 'invalid'
>
> I recommend that you review the memory management sections of the various
> Cocoa books available.
>
> If you requested a string without retaining it, then the string will be
> released at the time the autorelease pool is released.
>
> In general, if you use the a call that says "create", "copy", "alloc" then
> you have a reference and need to release it with either release or
> autorelease.  If you use a call that says "Get", etc. you do not have a
> reference and can generally only use it within a limited scope.
>
> Chas.
>
>
>> From: Graham <email@hidden>
>> Date: Wed, 31 May 2006 14:51:03 -0400
>> To: Apple CocoaList <email@hidden>
>> Subject: [OBJC newbie] - Intance variable becomes 'invalid'
>>
>> Just learning OBJC...
>>
>> I have a class with an NSString * instance variable.
>> Class has two methods, method a sets a value into the string, when
>> method b is called and tries to access the string it crashes my app.
>> gdb says the string instance is 'invalid'.
>> How can an instance variable become invalid? What does it even mean?
>> I suspect that since OBJC uses pointers everywhere that the instance
>> got stamped on somehow?
>> I have been living in the safe world of Java for too long I fear.
>>  _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Cocoa-dev mailing list      (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: [OBJC newbie] - Intance variable becomes 'invalid' (From: Chas Spillar <email@hidden>)

  • Prev by Date: Re: Use of weak reference in non-circular reference situation
  • Next by Date: Re: Re: [OBJC newbie] - Intance variable becomes 'invalid'
  • Previous by thread: Re: [OBJC newbie] - Intance variable becomes 'invalid'
  • Next by thread: Re: [OBJC newbie] - Intance variable becomes 'invalid'
  • Index(es):
    • Date
    • Thread