Results 1 to 10 of 10
- 01-21-2011, 05:49 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
profiler not showing decreasing Runtime.getRuntime().freeMemory() allocations
Here's an odd one I'm hoping people can help me with.
I'm writing a game, and am printing Runtime.getRuntime().freeMemory() onto the screen every frame.
What I'm finding is that the memory is starting at about 125 meg, and quite rapidly decreasing to about 50 meg, then jumping up to 125 meg (or there abouts) again, and then doing it again, and so on.
This suggested to me that a huge amount of memory is being allocated and discarded, and then freed by the garbage collector.
So I've profiled it in netbeans, and have taken a snapshop when it's at 125 meg and various others between, as I approach 50 meg.
But when comparing the profile reports, I see absolutely no new allocations accounting for that amount of memory. A meg or two at the most in small point / position classes, iterators and such, but that's it.
I'd like to be able to rely on having > 100 meg but I worry if I drop below 75 as the peak I'll run out of memory at the end of these cycles. Or will the GC run earlier / more frequently to compensate?
Anyone got any ideas what I could look for to find where this memory is going? :S
Thanks in advance,
lemmyLast edited by lemmy101; 01-21-2011 at 05:54 PM.
- 01-22-2011, 12:44 AM #2
Well, java does tend to fill all available space before running garbage collection, thats pretty common. As far as leaks, you might make sure that you are disposing of any Graphics or Graphics2D objects you are using. If you set the memory limits on java much lower, does it run out of heap space or does it exhibit similar behavior?
- 01-22-2011, 02:27 AM #3
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
I tried allocating a huge amount of memory so I only had 8 meg free at launch, and it avoided the out of memory error with garbage collects so I'm a happy coder :)
Still non the wiser where the memory is going, but as long as it comes back on demand with just a tiny pause, then I'm content for now. ;)
thanks! :)
- 01-22-2011, 05:50 AM #4
I'm sure you have a leak, or are trying to load way too much into memory at runtime, but without a code sample, its hard to say. Bitmaps (buffereImages) and the like use a LOT of memory in java since they are uncompressed. Its wise to load them as needed and to reuse sprites where possible.
- 01-22-2011, 11:27 AM #5
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
There's way too much to provide a code sample.
I figured out where the memory decrease is coming from. It seems to be happening in the pathfinding, if I comment that behaviour out the memory stays 100% static. It's weird though the profiler doesn't account for such a huge amount of memory :S any other free ones I could try?
- 01-23-2011, 12:31 AM #6
Are you putting things into an arraylist that doesn't get cleared?
- 01-23-2011, 12:31 AM #7
Or a recursive operation perhaps that continues to grow as you go? (Filling the system stack)?
- 01-23-2011, 05:36 PM #8
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
The only thing I can think of is iterator generation, I'm doing this (or rather code I've implemented into my project is doing this):
SortedList.add(Thing thing)
{
list.add(thing);
Collections.sort(list);
}
basically it's a sorted list class which is sorting the elements after each add. So iterators from the sort will be generated each time something is added to the list, and there is likely to be a lot of these per frame.
Is there a garbage free way to sort members of a collection in java? without writing your own sort function of course...
Either way, the thing that confuses me is the lack of reported allocations in the profiler. If it was items in an arraylist not getting cleared, or a recursive function allocating new memory, or a big bunch of iterators being garbage collected, then you would expect surely to see 75 megabyte of newly created objects in a comparative report of when the memory profiler snapshoted at 125 meg, and snapshoted when it was 50 meg (where it shows +/- memory / instances per type). I don't understand why the biggest memory change reported for a type is about 1.5 meg of data, and there is only about 4-5 meg extra accounted for in the entire profile results, no +75,000,000 bytes of Iter type listed or anything which seems like a massive number to go unaccounted for. Seems to me this means either memory profiling, or GetRunTime().FreeMemory tracking, is next to useless, as one of them is clearly either incorrect or omitting vital information.Last edited by lemmy101; 01-23-2011 at 05:42 PM.
- 01-24-2011, 12:48 AM #9
I'm not entirely sure... Are you sorting after every insert? Perhaps you should look at a different data structure?
- 01-24-2011, 12:17 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
passing arument to runtime.getRuntime() method
By cool in forum AWT / SwingReplies: 1Last Post: 11-12-2010, 06:15 AM -
Why can I use Runtime.getRuntime() in Eclipse
By ccie007 in forum New To JavaReplies: 5Last Post: 10-18-2010, 06:48 PM -
problem with Runtime.getRuntime().exec when running java in .bat
By Shayko in forum Threads and SynchronizationReplies: 2Last Post: 01-27-2010, 07:46 PM -
help with Runtime.getRuntime().exec
By collin389 in forum AWT / SwingReplies: 3Last Post: 11-09-2009, 04:22 AM -
grep on multiple files using Runtime.getRuntime().exec()
By cprash.aggarwal in forum Advanced JavaReplies: 3Last Post: 02-11-2009, 06:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks