Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
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  
  Garbage Collector  (Read 1843 times)
0 Members and 1 Guest are viewing this topic.
Offline SkyAphid
« Posted 2012-04-06 04:59:57 »

Okay, so I made a dungeon generator, and it works perfect. The only downside, is that it consumes all of my memory after generating new dungeons.

I've deducted that it may be in the list, rooms, because the generator generates Room objects, and stores it in the array list. Then, the tilemap is made by adding all of the widths and heights of the rooms IN that list. Thing is, I can't clear the list until I'm done with the dungeon, because references are made to each individual room for effects in the game.

Anyway, I get the heap space error after generating about 4 dungeons, and watching task manager, I can see Garbage Collector doesn't seem to be getting rid of the memory used by the last dungeon, and just accumulates the used memory until the game breaks.

I've taken all of the precautions to try and make sure the game doesn't run out of memory, but alas it hasn't worked.

This includes reinitializing all of the variables, clearing the room list, and mapTiles array before generating the new map.

What should I do? Sad

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Offline ReBirth
« Reply #1 - Posted 2012-04-06 05:56:40 »

Try to use profiler for more detailed of root of ebil.

Get rid everything that you used on previous dungeon by set to null and always remember to clear List or array after use. And the referenced objects too.

Offline SkyAphid
« Reply #2 - Posted 2012-04-06 06:08:01 »

Try to use profiler for more detailed of root of ebil.

Get rid everything that you used on previous dungeon by set to null and always remember to clear List or array after use. And the referenced objects too.

How do I "set to null"? I thought clearing the list got rid of all the objects.

EDIT:
I solved the problem by just making a simple workaround. I didn't want to resort to it for a few reasons...but I completely  reinitialize the entire object, which fixes the problem. If anyone can still help me overcome this, I'd be thankful.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 65K
« Reply #3 - Posted 2012-04-06 07:37:23 »

Either you still keep references of objects you don't need anymore or you simply did not assign enough memory to your game.
The various available garbage collectors have actually been quite perfected over the years, I think.

Setting to null is nothing more than:
objectX = null;

But you need to remove all references to be found.

Offline Danny02
« Reply #4 - Posted 2012-04-06 10:05:04 »

I never set anything to null, and think that this a very bad approach in java.
The Garbage Collector is there that you don't need to clear resources like in C, what setting something to null is doing.

I think your problem is that you are using global variables, which should be avoided.
Normally your Object should just get out of scope and get collected after that.

i.e.
You have a dungeon object, which is remembered in a reference in your game object.
When you enter a new dungeon, this reference just points to the new dungeon and the old will get automatically collected.
If you really need all dungeons every created to be stored in memory, you have to think about a new more memory efficient way to store them.
Offline 65K
« Reply #5 - Posted 2012-04-06 10:33:48 »

I never set anything to null, and think that this a very bad approach in java.
The Garbage Collector is there that you don't need to clear resources like in C, what setting something to null is doing.
No, usually you don't have to. Exceptions are for example array based collection classes like ArrayList or HashMap which have to null removed object references in order to trigger the GC.

Offline sproingie

JGO Kernel


Medals: 202



« Reply #6 - Posted 2012-04-06 15:30:42 »

If a single scope is so confused and overly large as to require explicitly nulling anything, you need to fix your design so you don't.  You should never have references in scope that are deliberately "broken".

I've had good luck with the Eclipse Memory Analyzer (http://www.eclipse.org/mat/), which does offline profiling of heap dumps.  There's a standalone version of it so even if eclipse isn't your preferred IDE you can still use it easily.


Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

PocketCrafter7 (14 views)
2014-11-28 16:25:35

PocketCrafter7 (9 views)
2014-11-28 16:25:09

PocketCrafter7 (10 views)
2014-11-28 16:24:29

toopeicgaming1999 (76 views)
2014-11-26 15:22:04

toopeicgaming1999 (67 views)
2014-11-26 15:20:36

toopeicgaming1999 (16 views)
2014-11-26 15:20:08

SHC (30 views)
2014-11-25 12:00:59

SHC (28 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!