Linked lists and the garbage collector of doom

Put your problem here if it does not fit any of the other categories.

Linked lists and the garbage collector of doom

Postby Resilient » Tue May 25, 2010 7:09 am

So, I am trying to essentially make a simple rope simulation except that the rope is not fixed length, I want to be able to add and take away from the ends.

It seemed to me that a simple linked list would be the ideal candidate for this but how can I implement this?

As I understand it, if I use Java's implementation, then garbage man cometh. And where comes the garbage man, so comes the 80ms pauses.

I am familiar with how I would roll my own in C but am less sure how to do the memory management in Java. I know I could just use an array for this with a unique identifier for the beginning and end of the rope, but I am doing this more to learn than to make a rope and linked lists seems like a useful structure. But if this isn't worth pursuing then I will just let it go and be happy with an array.

But then more generally, whats a good practice for handling dynamically sized data structures without invoking the wrath of the garbage collector? Or do you generally just make sure it starts big enough and leave it at that?

Thanks!
Resilient
Junior Developer
Junior Developer
 
Posts: 15
Joined: Tue May 18, 2010 1:33 am

Top

Re: Linked lists and the garbage collector of doom

Postby anarche » Thu May 27, 2010 2:22 am

No I think you're on the right path. You can't really "do" your own memory-management in Java without writing C-wrappers.

If you wish to amoritise the 80ms garbage collection cycle you can provoke it yourself with a call to System.gc().

I wouldn't really worry about this issue, especially for learning purposes. For a simple linked list the pause isn't really noticable - akin to the process-swap that happens when your comp does a context-switch
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: Linked lists and the garbage collector of doom

Postby nicholas.hauschild » Fri May 28, 2010 11:42 pm

Sounds like someone is a Java hater, or perhaps just living in the past.

For quite some time now, Java's garbage collection times have been negligible. With every release of Java, things are being improved everywhere, including the front on garbage collection (in Java7, which releases later this year, comes the G1 Garbage Collector, the latest and greatest from Java). If you are experiencing issues with garbage collection, perhaps the issue is actually a memory leak in either your code, or the third party jars that you are using.

While I AM a dedicated follower (and believer) of Java, I think it is fair to note that Android simply uses Java syntax. Android code is not compiled to java byte code, but rather into .dex files which are read by a Dalvik Virtaul Machine. I do not know how DVM handles garbage collection currently, but I am sure it is doing a fine job.

All in all, I am suggesting that you don't worry about 'the dreaded garbage collector', but instead worry about writing solid code :)

Good Luck!
-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Re: Linked lists and the garbage collector of doom

Postby nicholas.hauschild » Fri May 28, 2010 11:43 pm

Sorry, forgot to mention this...

If you still want to write in C, I suggest looking into the NDK (native development kit). I have not yet looked into it, but I hear that you can do some stuff in C there.
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 9 guests