Thanks guys
Yes, my problem is I still don't understand memory management.
I've changed the code to work with autorelease.
I want to add and remove the main menu when needed, so I want to completely remove the singleton's shared variable (menuPrincipalCompartido).
When i call "removeFromParent" from "Game.m" decreases the retain count to 0 and thus triggers the dealloc method, all right, but when I print the retain count of the shared variable in dealloc method it remains at 1.
How I can make the variable is removed from memory completely?
Here a part of my code:
#import "Menu_Principal.h"
//Shared variable
static Menu_Principal *menuPrincipalCompartido;
@implementation Menu_Principal
//Singleton Method
+ (Menu_Principal *)menu_principal
{
@synchronized(self){
if (!menuPrincipalCompartido) {
menuPrincipalCompartido = [[[Menu_Principal alloc] init] autorelease];
}
}
return menuPrincipalCompartido;
}
- (id)init {
if (self = [super init]) {
//Code... this method inserts SPButtons and SPTextFields with his events listeners
}
return self;
}
- (void)dealloc {
//returns 1
NSLog(@"Retain Count menuPrincipalCompartido: %i", [menuPrincipalCompartido retainCount]);
[super dealloc];
//Can I put here something like that?: menuPrincipalCompartido = nil; (?)
//returns 1 too (????)
NSLog(@"Retain Count Menu menuPrincipalCompartido: %i", [menuPrincipalCompartido retainCount]);
}
This generates a leak? And if I assign nil to the shared variable?
Do you understand me? Sorry i'm very very new in memory management