VS 2005 problems...?

Started by
15 comments, last by Will Vale 16 years, 10 months ago
Anybody please? Me and a friend of mine have narrowed it down to tMaterialInfo struct, inside the vector that holds that struct, thats the leak, but it appears to freeing everything fine...
Show A Man A Program, Frustrate Him For A Day...Teach A Man To Program, Frustrate Him For The Rest Of His Life...
Advertisement
Were you able to try the break on alloc technique?
Yeah, all the allocs and deallocs all match up, the problem is the stl::vector class...I changed the vector<tMaterialInfo> pMaterials and vector<t3DObject> pObjects to static arrays and no leaks detected...but I have no idea why a leak was detected using stl::vector...
Show A Man A Program, Frustrate Him For A Day...Teach A Man To Program, Frustrate Him For The Rest Of His Life...
Hmm. While (with tongue in cheek) I like to hear about the odd problem with STL as a counterpoint to all the STL boosterism on these forums, that doesn't help you much :(

So... do you manually call _CrtDumpMemoryLeaks or are you relying on the dump on exit flag? The std::vector<> destructor will definitely release the vector's memory to the free store, but I'm not sure if the same guarantee applies to clear().

If you've allocated your model on the stack or statically in your test harness, and you manually dump the leaks at the end of main() then the model might not have gone out of scope at the time of the dump. If it's still in scope, it won't have been destroyed, and memory owned by the vectors might not go away. That doesn't mean it's leaked, just that your leak check is too early.

If you're using the auto stuff already, then it's probably time to post your test harness as well.

Cheers,

Will

[Edited by - Will Vale on June 8, 2007 2:46:47 AM]
Hi Will, yeah I've had a few problems before with stl::vector class and memory saying it isn't being free'd.

I'm calling _CrtDumpMemoryLeaks() here:

WPARAM MainLoop(){	MSG msg;	while(1)												{															if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 		{ 			if(msg.message == WM_QUIT)									break;			TranslateMessage(&msg);									DispatchMessage(&msg);							}		else									{ 		   Run();		} 	}	g_Game.Shutdown();	_CrtDumpMemoryLeaks();	return( msg.wParam );									}


Game::Shutdown() is what is freeing all the 3D objects loaded...

Cheers!
Show A Man A Program, Frustrate Him For A Day...Teach A Man To Program, Frustrate Him For The Rest Of His Life...
Is that right?
Show A Man A Program, Frustrate Him For A Day...Teach A Man To Program, Frustrate Him For The Rest Of His Life...
Sorry, didn't see the reply for a while. You're reporting the leaks in the wrong place. Rather than calling _CrtDumpMemoryLeaks(), you need to set the debug flags at the top of WinMain:

_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

Then you don't need to dump the leaks explicitly, and they'll be checked for when all file-scope objects have been destroyed. This should demonstrate that std::vector isn't leaking.

Will

This topic is closed to new replies.

Advertisement