Memory Manangement with NSMutableArray
Memory Manangement with NSMutableArray
- Subject: Memory Manangement with NSMutableArray
- From: Mike Burns <email@hidden>
- Date: Sun, 13 May 2007 12:16:28 -0400
I've been reading through every memory management doc that comes up
with a google search and I can't seem to figure out how to solve the
problem I have. I'm fairly sure it is some sort of memory leak, but
I can't find the source. Here is the setup:
In my app I have a window which contains a subclass of NSView
(SceneView) and a controller object (SceneController) which handles
menu commands, etc. In addition I have two classes I created - Scene
and SceneElement:
@interface Scene : NSObject <NSCoding>
{
NSMutableArray *elements;
NSString *sceneName;
NSRect sceneWinFrame;
NSRect textWinFrame;
}
@interface SceneElement : NSObject <NSCoding>
{
NSBezierPath *shape;
int shapeType;
NSColor *strokeColor;
NSColor *fillColor;
float lineWidth;
BOOL isSelected;
}
Now everything works fine usually. The problem occurs when I try to
load a Scene (which was archived to a file using NSKeyedArchiver).
It loads the scene alright and draws it correctly -- but when I try
to delete one of the SceneElements (from the currentScene's elements
array) the program hangs. I am positive this is some sort of memory
problem -- but I'm not sure the correct way to go about it so I don't
know how to fix it. Here are some additional methods:
- (void) addElement: (SceneElement*)obj
{
[ elements addObject: obj ];
}
- (void) deleteElement: (SceneElement*)obj
{
[ elements removeObject:obj];
}
These are in the Scene class -- the SceneElement* that is passed in
to it was created in the SceneView. The code that actually deletes
the element from the array is in my SceneView class:
- (void) keyDown: (NSEvent*)event
{
unichar key = [[event charactersIgnoringModifiers] characterAtIndex:0];
if( key == NSDeleteCharacter )
{
if( objectIsSelected == YES)
[ currentScene deleteElement: selectedObject ];
}
[ self setNeedsDisplay:YES ];
}
I'm sorry for all the code -- I really appreciate any help!
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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