0 votes
asked by (390 points)
Hello everyone!

Is there are way to "uncache" audio to clean up the RAM a bit? I already looked up on sugarcubes site but haven't found anything.

1 Answer

0 votes
answered by (32.6k points)

If we assume the variable _trackID equals the track ID of the track you want to uncache, then you would do this:

<<set _tracks = Macro.get("cacheaudio").tracks>>
<<if _tracks.hasOwnProperty(_trackID)>>
	<<if _tracks[_trackID].audio.duration>>
		<<run alert('Error: Cannot uncache track "' + _trackID + '".  Track currently queued for playing.')>>
		<<run _tracks[_trackID].destroy()>>
	<<run alert('Error: Track "' + _trackID + '" not found.')>>

That will display error popups if you attempt to delete a track that doesn't exist or a track that is currently queued for playing (currently playing or paused).  You can swap out those "alert" lines for your own error handling method if you prefer.

Note that this may not immediately free up that memory, however, it should make that memory available for JavaScript garbage collection.

Hope that helps!  :-)

[Note: I haven't tested the above code, but I believe it should work.]

commented by (390 points)

Thank you very much for your help. If i am reading the code correctly, then is this:

<<run _tracks[_trackID].destroy()>>

the actual part which deletes the track, right? Don't get me wrong. I appreciate the help but i actually only need a command to uncache music as soon as the player gets to the next chapter.

Second: The trackID is the name from the track right? Like:

<<cacheaudio "theme" "music/theme.mp3">>

In this example the trackID would be "theme", or?

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.