Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close MIDI Player to prevent memory leak #23

Closed
quadpixels opened this issue Dec 7, 2017 · 0 comments
Closed

Close MIDI Player to prevent memory leak #23

quadpixels opened this issue Dec 7, 2017 · 0 comments

Comments

@quadpixels
Copy link
Contributor

quadpixels commented Dec 7, 2017

public void deallocate() { state = Player.CLOSED; }

Hello Hex007!
I think calling MidiSequencer.close() when deallocating a player which is an instance of a MIDI player can help prevent memory leak. (There is a particular game that re-creates a MIDI player every time when the character enters a new scene, so after entering 100 scenes or so the program starts to consume ~600 MB of memory and have ~200 running threads.)

On Linux, having more than a few MIDI players will cause the music to stop, but this doesn't happen on Windows.

The fix may look like the following:

public void deallocate() {
	stop();
	if (player instanceof midiPlayer) {
		((midiPlayer)player).midi.close();
	}
	player = null;
	state = Player.CLOSED;
}

Thanks!

p.s. A similar issue and the usage of close() is mentioned in this Stackoverflow post: Java Sequencer using all memory? (7kb midi file)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant