[LibGDX] Memory leaks are killing me......

Good evening,
first of all, I’m new here.
I’m having some serious issues with some memory leaks. Let me expalin in detail:
My game (it is an android game) is composed of 3 game screens, on is the main menu with the option tab, one is the pre-match menu, and the last is the in-game screen.
My game is working perfectly but crashes very often due to what I think are memory leaks.
When my game crash, I don’t get any error message from the game log, but in the general android log I see:

[quote]09-08 17:23:45.718: E/InputDispatcher(376): channel ~ Channel is unrecoverably broken and will be disposed!
[/quote]
When I switch from a game screen to another, I always call .remove() to my objects (like buttons, labels etc) and I’ve a list of disposable items that I just dispose using an iterator.
I switch from a game screen to another using: game.setScreen(new gameMenu(game, actionResolver));
Now I’ve also some questions:

  1. is there a way to completely destroy the old screen class when I switch game screen ? for example, to completely remove gameMenu() when I switch to gamePrematch(), since I don’t need gameMenu() anymore. I’m asking this because in that way would be simple to avoid memory leaks, because if I’m not wrong, when the class will be destroyed, the GC will collect every variable that existed in the class.
  2. in the ingame screen, I’ve some functions that declare some images in that way:
 Image player = new Image(new Texture(Gdx.files.internal("data/player.png")));

when I call player.remove() will the GC clean also the texture object ??
3) Maybe my problem is not releated to memory leaks and I’m missing something ?? what do you think about ??

Thank you very much

Have you tried the debugger to narrow down the block(s) of code that it breaks at?

As far as I remember there is a destroy method on almost all objects :slight_smile: Image::destroy

the destroy method doesn’t exist in libgdx objects. They have the remove() method…

[quote]Have you tried the debugger to narrow down the block(s) of code that it breaks at?
[/quote]
it breaks when it reach a certain number of objects ( logged with DDMS and heap tracker)

it seems that the GC doesn’t clean some objects

Could be a timing thing if it doesn’t happen every time. Maybe something like there’s still events coming in from the input - finger-up or something - when you remove one screen, and sometimes there’s time for them all to get handled and sometimes there’s not, in which case you’ve removed the object but android still tries to dispatch an input event to it. Would depend what kind of threading you’re doing I guess. I don’t know much about android event handling.

It is not a timing issue because it always crash when reach a certain number of objects in the heap

It’s dispose() that LibGDX uses. That releases the texture contexts and everything.