Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (762)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (846)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LibGDX] Memory leaks are killing me......  (Read 6235 times)
0 Members and 1 Guest are viewing this topic.
Offline Luca91

Junior Newbie





« Posted 2014-09-08 17:22:01 »

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!

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:
1  
 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
Offline Warden
« Reply #1 - Posted 2014-09-08 18:09:28 »

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

JGO Knight


Medals: 61


Manager Developer Relations @Hazelcast


« Reply #2 - Posted 2014-09-08 18:12:15 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Luca91

Junior Newbie





« Reply #3 - Posted 2014-09-08 18:25:06 »

As far as I remember there is a destroy method on almost all objects Smiley 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?
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
Offline richierich
« Reply #4 - Posted 2014-09-08 18:31:51 »

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.
Offline Luca91

Junior Newbie





« Reply #5 - Posted 2014-09-08 18:36:29 »

It is not a timing issue because it always crash when reach a certain number of objects in the heap
Offline UprightPath
« Reply #6 - Posted 2014-09-08 19:07:20 »

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

Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (354 views)
2018-06-10 19:43:48

EgonOlsen (355 views)
2018-06-10 19:43:44

EgonOlsen (295 views)
2018-06-10 19:43:20

DesertCoockie (530 views)
2018-05-13 18:23:11

nelsongames (846 views)
2018-04-24 18:15:36

nelsongames (833 views)
2018-04-24 18:14:32

ivj94 (1273 views)
2018-03-24 14:47:39

ivj94 (397 views)
2018-03-24 14:46:31

ivj94 (1067 views)
2018-03-24 14:43:53

Solater (415 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!