memory issue when passing the cclayer to my objects
===

I've got a CCLayer where I want to add many buttons. 
I created the class MyButton with this init function:

    -(id) initWithLayer:(MyLayer *)theLayer andDictionary:(NSDictionary *)data

This init function will add the buttons to the layer and I'm managing all the behaviour (movements, image changes) in the MyButton class.

So the layer is being sent to all the MyButton instances. The layer won't call the dealloc method until each button is released.

These buttons are being added to the layer through an array:

    _buttons = [[NSMutableArray alloc] init];
    for (NSDictionary *buttonData in buttonsArray) {
       MyButton *btn = [[MyButton alloc] initWithLayer:self andDictionary:buttonData];
       [_buttons addObject:btn];
       [btn release];
    }

My problem is that when I replace this scene, the dealloc methos of MyButton is not being called and the memory is not being released, cause the [_buttons release] is in the dealloc method of the layer, which is not being called either, cause the layer has been passed to each button.

It's a mess. Can anyone tell me the best way for fixing this memory problem?



