Memory leak detected

Hello,

I created a new project (multi-platform using command line), and adding

#if defined(DEBUG) | defined(_DEBUG)
  _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

to _tWinMain (in main.cpp). When exiting/closing the application the output results in this:

cocos2d: deallocing CCDirector 025C5DD0
The thread 'Win32 Thread' (0x1914) has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
{199} normal block at 0x025C61C0, 4 bytes long.
 Data: <    > 00 00 00 00 
Object dump complete.

No modifications has been made to code except for the mem leak check snippit. Removing the “Hello World” code from init() (in HellowWorldScene.cpp) has the same result.
Used MSVC2010 and version 2.1.3 of Cocos2dx.

Could it be because of how I installed or setup Cocos2d/projects? Anyone else getting memory leaks?

Are you seeing the same result on TestCpp?

Yeah, and on HelloCpp.

I tested version 2.1.2 of Cocos2dx as well, and got the same results.

This is what I get for even the most basic Cocos2d-x application:

Detected memory leaks!
Dumping objects ->
{156} normal block at 0x00D56730, 4 bytes long.
 Data: <    > 00 00 00 00 
Object dump complete.

Testing with Visual Leak Detector I don’t see that 4 bytes, maybe it is a false positive.

Yeah, could be, everything else releases correctly with no leaks or problems.
I haven’t had a look at the disassembly yet, but I guess this is a minor issues if an issue at all.

Thanks for the Visual Leak detector check, I’m guessing the problem could be with _CrtSetDbgFlag( *CRTDBG_ALLOC_MEM_DF |*CRTDBG_LEAK_CHECK_DF ) checks, will have to read up on it again.

Great free tool…

I really wish I could say I have no leaks or problems, still struggling with that here.

I’ve never had any issues keeping Objective-C in check but C++ is giving me fits :wink:

Thanks, its quick and easy to use. I installed VLD, included it and ran the projects, and it detected no leaks. So I’m going to go with what it says and happily continue coding :slight_smile:

Until now I only used the _CrtSetDbgFlag checks for c*+ coding. Haven’t coded in ObjectiveC yet, but until now I’ve had no trouble with mem leaks and such in c*+.

maybe there were just some Share** objects!

Don’t know if it will help, but I have memory leak on cocos2dx-2.0_2.1.4. Just write Test with boost\test and #include “CCApplication.h” and you will have memory leak:
{693} normal block at 0x00487940, 4 bytes long.
Data: < > 00 00 00 00

Michael Deepscorn wrote:

Don’t know if it will help, but I have memory leak on cocos2dx-2.0_2.1.4. Just write Test with boost est and #include “CCApplication.h” and you will have memory leak:
{693} normal block at 0x00487940, 4 bytes long.
Data: < > 00 00 00 00

That’s a bug in the leak detector.

Just did some tests with VS2012, cocos2d-x 3.2 and a clean HelloWorld. Found the memory leak is possibly caused by calling CCLOG with other function calls in it. Both _CrtSetDbgFlag and ALD methods won’t report memory leaks anymore after removing all CCLOG callings.