Sign in to follow this  
BrianJensen

[JAVA] Image & AudioClip

Recommended Posts

when you load a resource do you have to then remove it? and if so how?

 

[code]        Click = getAudioClip(this.getClass().getResource("/Sprites/Audio/click.wav"));
        BlackPiece = getImage(this.getClass().getResource("/Sprites/BlackPiece.png")); .......         private AudioClip Click;         private Image BlackPiece; ........[/code]

Edited by 0Circle0

Share this post


Link to post
Share on other sites
Java is a high-level programming language, and therefore does a lot of management for you in its virtual machine (JVM). One such thing is a garbage-collecting system. Once the JVM's garbage collector detects that your variable isn't being used anymore, it frees up that area in memory. So your short answer for that is no.
If you're concerned about using space however, you can model your objects in a way that removes references when they're "destroyed," prompting the garbage collector to remove them. If you know you're going to have multiples of that same class being displayed, it may also be a good idea to make your Images and AudioClips static, so you only need to instantiate one, rather than create a new one for every instance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this