Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayList.remove(index), is it viable for garbage collection?

When creating a game and you want to delete something from the screen that is in an ArrayList, lets say a bullet, is it viable to use arrayList.remove(index) to remove it from the game? or is it still using up memory when done this way?

If this is not the preferred way to do it, please point me in the right direction :)

like image 952
Green_qaue Avatar asked Jul 29 '13 22:07

Green_qaue


1 Answers

The answer is possibly. Removing the bullet from the ArrayList will eliminate a reference to it. If there are no other references, then the bullet object will be GCed eventually.

The screen of course will have to redraw itself without the bullet and that is a mostly separate issue.

like image 63
Tim Bender Avatar answered Sep 28 '22 02:09

Tim Bender