cocos2d/cocos2d-x — pull request #2439 by chbuck (2013-04-24 08:12:23+00:00)
Title: CCMenuItem: fixed crash while removing itself

WhenCCMenuItem is clicked, the CCMenuItem::activate() method will call your target->selector. If you remove the menu item within this target->selector method (because it is an exit button), your CCMenuItem will be released and destroyed while CCMenuItem::activate() method is still running. Sometimes it crashes!

A fix for that problem is to retain and release the CCMenuItem in its activate() method. This way it will be destroyed earliest when CCMenuItem::activated() has been finished.

This problem is also documented here: http://www.cocos2d-x.org/boards/6/topics/25625