Hi,
I am running XCode 3.2.2 with Garbage Collection required.
Something strange is happening with NSAllocateCollectable.
I am hoping someone will instantly recognise the symptoms and tell me what I'm
doing wrong.
Distinct memory allocations using NSAllocateCollectable are allocating the same
portion of memory.
Create a Cocoa Application, create a subclass of NSObject, call this MyControl
and instantiate it in the MainMenu.xib with a reference to it in the
AppDelegate.
Define a new nib: NibWindow.xib and include it in the project.
Define a NSWindowController, MyWindowController say, and make it the
NibWindow's File's Owner.
Give MyControl a button which causes it to create a new MyWindowController;
Inside MyControl define three pointers of type CGFloat , e.g CGFloat * mem1,
mem2, mem3;
and declare them as @property GFloat * mem1; etc with corresponding @synthesize
statements.
Declare a MyControl method that allocates memory to mem1 etc, e.g.
self.Mem2 = (CGFloat *)NSAllocateCollectable((sizeof(CGFloat) *
22000),NSScannedOption);
Declare exactly the same variables and methods in MyWindowController. Change
the names of the variables if you like, makes no difference. Allocate memory as
above. Each of the variables in the sequence now contains the same pointer
value as the corresponding variable in MyControl and each of the other
MyWindowController instances. Assign a set of values to each of the arrays in
MyControl. Those very same values appear in the arrays in the
MyWindowController instances. Change the array values in one of the
MyWindowController instances and the change also appears in the other instances
and MyController.
Allocate new memory to the MyControl variables. The pointer values are again
the same and all of the arrays are zeroised. Modify one and the change will
also appear in the other objects.
It seems then that calling NSAllocateCollectable several times in a row within
a given method causes several new blocks of memory to be allocated as expected.
But do this in another method, even if it is in the same object and the exact
same blocks of memory are allocated. That is, each sequence of calls to
NSAllocateCollectable within a given method appears to cause it to go through
the exact same sequence of steps and draw memory from the exact same memory
pool.
I thought that perhaps the problem occurred because of how I defined the
properties but no. Even if I do not define any setters or accessors and access
the variables directly the same thing happens.
Note that other variables declared within MyWindowController retain their
unique values so it looks as if it must be NSAllocateCollectable that is
causing the problem.
Que passa?
What am I doing wrong ?
Julius
------------------------------------------------------
http://juliuspaintings.co.uk
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]