FMOD causing memory leaks?

Started by
16 comments, last by L. Spiro 10 years, 2 months ago

Then you have a memory overflow bug somewhere in your application that is corrupting memory around the System object, you are deleting it twice, or the pointer was not created via new.

Since it was created via FMOD::System_Create(), why are you deleting it? Tutorials show to just call System->release().

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Advertisement


why are you deleting it?

I'm still learning C++ and thought I had to delete it because it was a pointer. lol

I would recommend grabbing the return value from System::release(). You might get an error from that which would tell you what is wrong. In any case, an error on release() would probably result in leaks.

I might be wrong on this, so you'll have to do a little homework to make sure. I think you're supposed to have a close() call paired with the init(), and release() gets paired with the create(). You'll also really want to pay attention to the errors that get returned for every part you shut down. Later, you'll probably have quite a few components to shutdown and they have to be in the right order. You'll also have calls that can fail if the hardware is still in use from a prior sound call, and other stuff like that.

Just a stab in the dark, but are you allocating something and putting it in 'System' before you pass 'System' to FMOD::System_Create()? If so, then don't (that would cause a memory leak).

A few miscellanea:

*Don't ZeroMemory() the pointer. That's just silly.

*As was indicated, if you set the pointer to null and then delete it, you should be getting a segfault. Don't do that. (There's no reason to do either of those things. FMOD will free the memory it allocated when you call System->release().)

*No offense, but why does this class exist? All it appears to do is act as more-or-less a direct pass-thru for the FMOD system interface.

Please read the documentation that came with FMOD about how to start up the system correctly. It's on page 8 of "Getting started with FMOD for Windows.pdf".

Please research the RAII design pattern. Mastering RAII is the 'correct' way to avoid memory leaks in C++, and it also helps with things like exception safety and even makes it easier and more natural-feeling to use your objects!

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.


if you set the pointer to null and then delete it, you should be getting a segfault.

NULL pointers are always safe to delete/free().

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Oh, right. I forgot that. derp

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Sorry it took so long to reply! I've been busy. I have a question. If the memory leaks only happen during initialization, is that a big problem? As long as my application is not creating leaks during runtime, am I correct? I noticed that on my applications startup with GlowCode enabled, it finds the leaks when I search, but if I click Clear, and search for memory leaks then, I get 1 leak with VSync off (On my swapchain's Present method) and 0 with VSync on. Thanks! smile.png

If the memory leaks only happen during initialization, is that a big problem?

All leaks should be treated seriously. It is extremely bad practice to let the operating system clean up your messes on application shut-down and I would never hire someone who disagreed with that.
The people who do that will be the ruin of your project some day.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement