Jump to content
  • Advertisement
Sign in to follow this  
KoldGames

FMOD causing memory leaks?

This topic is 2092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello!  I was using GlowCode to find memory leaks and saw that FMOD seems to be causing some:

przu.png

erwj.png

bbe6.png

Any help? Thanks! smile.png

Edited by KoldGames

Share this post


Link to post
Share on other sites
Advertisement

I can't see anything from the pictures, so this is 100% blind guesswork.

 

First, I'll guess you're talking about the sound library since obviously the FMOD instruction can't cause a leak and no other fmod jumps out at me. If that's the case, are you calling FMOD::Sound::release() after you finish using a sound? Being able to read the pictures might provide a better idea what functions you're calling and not calling for a better guess, but I just can't read the text in those pictures at all.

Share this post


Link to post
Share on other sites

Without really knowing anything about FMOD, it looks like the supposed leaks are in its initialization functions. Are you sure you are doing everything you need to do to properly unintialize FMOD prior to exiting your game?

Share this post


Link to post
Share on other sites

Are you calling System::release() when you're exiting your program? It looks like all of the leaks are from init(), so it's not memory constantly leaking or something. It's not even memory you'd ever have available for use during normal execution of your program (unless you release and create FMOD a lot, which you shouldn't).

 

If you are calling release(), make sure you're not nulling any relevant pointers or stomping on FMOD's memory or such before calling release() since you had your entire program's execution time to accidentally corrupt the data needed by FMOD to shutdown correctly.

Share this post


Link to post
Share on other sites

Are you sure you are doing everything you need to do to properly unintialize FMOD prior to exiting your game?

 

Yep, I believe so.  I call System::Release(), then set System to NULL, and delete the pointer.

 

 

 


If you are calling release(), make sure you're not nulling any relevant pointers or stomping on FMOD's memory or such before calling release() since you had your entire program's execution time to accidentally corrupt the data needed by FMOD to shutdown correctly.

 

I tried removing any FMOD related code from my application while only leaving the NXAudio's Initialize, Update, and Dispose functions, but still have a memory leak.  Very weird.

 

Here's my NXAudio class code:

FMOD::System* NXAudio::System = nullptr;
		FMOD_RESULT result;

		bool NXAudio::Initialize()
		{
			ZeroMemory(&System, sizeof(FMOD::System*));

			result = FMOD::System_Create(&System);
			if (result != FMOD_OK)
				return false;

			result = System->init(100, FMOD_INIT_NORMAL, 0);
			if (result != FMOD_OK)
				return false;

			return true;
		}

		FMOD_RESULT NXAudio::Update()
		{
			return System->update();
		}

		void NXAudio::Dispose()
		{
			if (System)
			{
				System->release();
				System = nullptr;
				delete System;
			}
			
			return;
		}

		FMOD_RESULT NXAudio::CreateSound(const char* name, FMOD_MODE mode, FMOD_CREATESOUNDEXINFO* exInfo, FMOD::Sound** sound)
		{
			return System->createSound(name, mode, exInfo, sound);
		}

		FMOD_RESULT NXAudio::CreateStream(const char* name, FMOD_MODE mode, FMOD_CREATESOUNDEXINFO* exInfo, FMOD::Sound** sound)
		{
			return System->createStream(name, mode, exInfo, sound);
		}

		FMOD_RESULT NXAudio::PlaySound(FMOD::Sound* sound, FMOD::ChannelGroup* channelGroup, bool paused, FMOD::Channel** channel)
		{
			return System->playSound(sound, channelGroup, paused, channel);
		}

The ZeroMemory line wasn't there before, I added that last night when I was trying to fix the leak.  The leak won't go away with or without.  I set FMOD up exactly like the documentation says (aside from having it in a static class).  Could the fact that System is static be the problem?

Edited by KoldGames

Share this post


Link to post
Share on other sites


 I set FMOD up exactly like the documentation says (aside from having it in a static class).  Could the fact that System is static be the problem?

 

While it may be bad practice, it shouldn't really make a difference, since System is just a raw pointer (and so you're not relying on any kind of automatic destruction). You've verified by stepping through the debugger that NXAudio::Dispose is called and System->release gets called?

Share this post


Link to post
Share on other sites


You've verified by stepping through the debugger that NXAudio::Dispose is called and System->release gets called?

 

Yep!  I put a breakpoint on it and it is being called.

Share this post


Link to post
Share on other sites

 

Here's my NXAudio class code:

		void NXAudio::Dispose()
		{
			if (System)
			{
				System->release();
				System = nullptr;
				delete System;
			}
			
			return;
		}

 

Delete should be before setting to nullptr.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!