In menu screens i typically see this in Ricardo's code (init Method):
Menu *menu = [Menu menuWithItems:item1, item2, item3, item4, nil];
[self addChild: menu z:0];
menu is never again referenced in the code. So when exactly is the memory used by memory freed? Doesn't this leak memory or cause the memory only to be freed when quitting the application?
Second question. We started following the "always alloc" rule. In our code we do this in the init Method (menu is now a member variable):
menu = [[Menu alloc] initWithItems:(MenuItem*)buttonBackground vaList:(va_list)dummyList];
[self addChild: menu z:0];
and in the dealloc method we do this:
[[menu parent] removeChild:menu cleanup:YES];
[menu release];
Actually that was my colleague adding the first line. He insists that otherwise any alloc'ed object added to the cocosnode won't be cleaned up propery. Personally i doubt this. Can someone clarify this for us please: is the first line really necessary, and is it really necessary to alloc menu screen objects where we don't care so much about performance?