Re: Static Variable Question...
Re: Static Variable Question...
- Subject: Re: Static Variable Question...
- From: "R. Tony Goold" <email@hidden>
- Date: Sat, 21 Jul 2001 17:28:46 -0400
On Saturday, July 21, 2001, at 01:52 , Joshua D. Orr wrote:
>
I think what's happening is when the program loads the new document, it
>
sets the static variables to point to the new NSArrays, and both the old
>
document and the new one point to the same NSArrays.
That sounds like the correct behaviour. Static variables are shared by the
class. If you want each document to have its own values, you should be
using instance variables. What is the reason for using a class method to
access the variables? It should be possible to turn it into an instance
method.
>
I was hoping separating the objects into different zones would make the
>
class static variables separate also (one for each zone).
I don't know much about ObjC's implementation, but in Java the static
variables are handled by the class loader. The only way to get two
instances of a static class variable in Java is to have a class loaded by
multiple class loaders simultaneously. I haven't seen that part of the
runtime environment exposed in ObjC in anything I've read so far. Even if
it were, I don't think that would be the appropriate solution to your
problem.
>
Does anyone have any ideas?
I would see about making that class method into an instance one. Make an
-(id)initWithArrays:(NSArray *)arrays method and call that. If the object
that calls the method doesn't have a pointer to your object, you should
find a way of providing it with one instead of relying on side effects to
preserve distinct instances of a static variable.
Cheers,
Tony