Streaming Audio Memory Leak
by Gellyware · in Torque Game Builder · 09/19/2006 (3:02 pm) · 8 replies
It seems that streaming an audio sound causes a memory leak that increases each time a new streaming sound is called.
An example of what I am using exactly is this:
And here is the 'music jukebox' code that works within a game framework that I'm putting together:
In a matter of about an hour, the memory from the game tripled in memory usage and was just sitting idle, playing a random song after one was finished. I'm going to let it run all night tonight to get an estimate of how a longer term use will affect the memory leak.
An example of what I am using exactly is this:
$musicChannel = 1;
new AudioDescription(AudioStreaming)
{
volume = 1.0;
isLooping = 0;
is3D = 0;
isStreaming = 1;
preload = 0;
type = $musicChannel;
};
new AudioProfile(smoothJazz1)
{
filename = "~/data/audio/smoothJazz1.ogg";
description = AudioStreaming;
};
new AudioProfile(smoothJazz2)
{
filename = "~/data/audio/smoothJazz2.ogg";
description = AudioStreaming;
};
new AudioProfile(smoothJazz3)
{
filename = "~/data/audio/smoothJazz3.ogg";
description = AudioStreaming;
};
new AudioProfile(smoothJazz4)
{
filename = "~/data/audio/smoothJazz4.ogg";
description = AudioStreaming;
};
new AudioProfile(smoothJazz5)
{
filename = "~/data/audio/smoothJazz5.ogg";
description = AudioStreaming;
};And here is the 'music jukebox' code that works within a game framework that I'm putting together:
function game::musicJukeboxPlay(%this)
{
//if the game music is off or the game is over then return
if(!$game.music || $game.over)
return;
%samplePrefix = $game.musicSamplePrefix; // "smoothJazz"
%sampleMin = $game.musicSampleMin; //"1"
%sampleMax = $game.musicSampleMax; // "5"
//make sure we get a random sample to play
%done = false;
while(!%done)
{
%random = getRandom(%sampleMin, %sampleMax);
%temp = %samplePrefix @ %random;
if(%temp !$= $game.musicSamplePlaying)
%done = true;
}
//assign our musicSample playing so that we can tell
//which one was last played for future randomization
//in order to make sure that the song isnt played twice in a row
$game.musicSamplePlaying = %samplePrefix @ %random;
//stop the music from playing
alxStop( $game.musicChannel );
$game.musicChannel = alxPlay($game.musicSamplePlaying);
//find out how long our music sample is in millesecs
%songLength = alxGetStreamDuration( $game.musicChannel ) * 1000;
//schedule the music to play again and give some delay between songs
%delay = 500;
$game.schedule(%songLength + %delay, musicJukeboxPlay);
}In a matter of about an hour, the memory from the game tripled in memory usage and was just sitting idle, playing a random song after one was finished. I'm going to let it run all night tonight to get an estimate of how a longer term use will affect the memory leak.
About the author
#2
09/19/2006 (6:40 pm)
I remember hearing from someone (perhaps here on the boards, perhaps on irc) that the Windows task manager can be misleading, as it reports the peak amount of ram usage by a process and not the current amount. Could be something to consider whilest investigating this leak issue..
#3
Shouldn't the garbage collector clear this extra 'unused' memory at some point?
Is there a way to force collection on an object?
09/19/2006 (9:28 pm)
So how does one know if this should be a big concern or nothing to worry about? If the issue is legit, it's a big concern since after playing a game for a while. the game will likely have some negative effect on the end user machine (crash, sound act up, etc). If it isn't a legit issue then of course there is nothing to worry about. My concern is that the memory (on the task manager) is consistently going up and not down. Shouldn't the garbage collector clear this extra 'unused' memory at some point?
Is there a way to force collection on an object?
#4
09/20/2006 (1:41 am)
I don't think there's a scriptable way to force collection, unfortunately. I'd say continue with your test as planned; let it run overnight. If it hits the limit of free RAM and stops, probably functioning as intended. If its a real leak, it'll keep eating memory until the swap starts thrashing and will eventually crash.
#5
The memory used by the game only increases when a new song is streamed.
Here are the results so far:
Start Time: 2:21PM
2:21PM 95,584 KB
4:06PM 121,412 KB
4:30PM 127,084 KB
4:37PM 129,172 KB
4:54PM 133,300 KB
5:33PM 143,104 KB
6:03PM 150,264 KB
6:49PM 161,680 KB
I'm not going to keep posting about the incremental nature of streaming sound. This issue needs to be fixed as it appears to be a problem. If it isn't, I'd like to know from the GG team that it isn't. In four hours, the memory rose 66,096 kb. Without dropping.
I will like to point out that if a window is minimized by pressing the - on the window, the memory drops down tremendously (to 6,504k). What's really going on here?
09/20/2006 (2:42 pm)
I forgot to run the tests last night, but I'm gonna leave it running all evening and tonight to see what happens. As for running out of memory, my pc is at 3GB so I don't see that happening within a day or two. The memory used by the game only increases when a new song is streamed.
Here are the results so far:
Start Time: 2:21PM
2:21PM 95,584 KB
4:06PM 121,412 KB
4:30PM 127,084 KB
4:37PM 129,172 KB
4:54PM 133,300 KB
5:33PM 143,104 KB
6:03PM 150,264 KB
6:49PM 161,680 KB
I'm not going to keep posting about the incremental nature of streaming sound. This issue needs to be fixed as it appears to be a problem. If it isn't, I'd like to know from the GG team that it isn't. In four hours, the memory rose 66,096 kb. Without dropping.
I will like to point out that if a window is minimized by pressing the - on the window, the memory drops down tremendously (to 6,504k). What's really going on here?
#6
Should this apparent memory leak be a concern?
09/21/2006 (12:13 pm)
Can someone from GG please respond to this issue? Should this apparent memory leak be a concern?
#7
A proper test would be to try it on a machine that has only 256MB of RAM. If the above theory is right, the memory usage should be lower simply because there is less RAM available to the system as a whole.
09/21/2006 (12:36 pm)
In a previous thread about memory, it was mentioned that TGB (and presumably TGE) eats as much memory as it needs, as long as there is plenty availble.A proper test would be to try it on a machine that has only 256MB of RAM. If the above theory is right, the memory usage should be lower simply because there is less RAM available to the system as a whole.
#8
09/21/2006 (3:44 pm)
Thanks Phillip, I'll run some more tests. What are the minimum requirements to run TGB?
Torque 3D Owner Luke D
Default Studio Name