[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Life of instance variables?
From: |
Albert Chun-Chieh Huang |
Subject: |
Re: Life of instance variables? |
Date: |
26 May 2003 19:36:34 +0800 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
Albert Chun-Chieh Huang <jjhuang@cm.nctu.edu.tw> writes:
> Dear all,
> My question is about instance variable. Let me explain in details:
> Node and MyNode is two classes, their relationship is
> MyNode : Node : NSObject, where MyNode is a subclass of Node.
> In my code, there is only instances of MyNode, for Node is an abstract
> class.
[stuff deleted]
Sorry, I found an interesting thing. I add some NSLog to Node class to
print out [[self description] cString]. I found the memory location
changes every time. And after tracing the bug, I found that I made a
BIG mistake. I forgot that, in NSMutableDictionary, key will be
*copied* while I thought it was *retained*. I used NSMutableDictionary
to record Nodes which is ready to receive packets as a key. After
finding this, I've corrected my code. I don't use Node as a key for
the dictionary now. I use it as a value, and it works as expected now.
Sorry, I always looked up Foundation classes in OpenStep specification
on October 19, 1994. And it doesn't mention this. I searched documents
on GNUstep.org. Finally, I found some documents about this.
Thanks for helps.
Best Regards,
Albert
--
Chun-Chieh Huang, aka Albert | E-mail: jjhuang AT cm.nctu.edu.tw
黃俊傑 |
Department of Computer Science |
National Tsing Hua University | MIME/ASCII/PDF/PostScript are welcome!
HsinChu, Taiwan | NO MS WORD DOC FILE, PLEASE!