Top.Mail.Ru
August 14th, 2008 - Java developers — LiveJournal
? ?

Java developers

August 14th, 2008
Image

02:37 pm - Imagespecialagentm - Freeing up memory quicker?

I'm not expert on JVM garbage collection routines, so I'm wondering if this code actually does anything useful. I have a need to copy around what might be a large data structure (possibly deep copying, so I'd actually have double the memory usage). Past a certain point in a routine, I don't need copy #1 anymore, and I'm about to call another method that might take some time (it does a network call and won't return until it is done or it times out)

So, does this code help that at all? (Yes, this is heavily pseudo-coded and contrived, but the real code doesn't matter so much as the portion highlighted below)

public void doSomething()
{
  List messageList = UtilClass.makeMessageList();
  List messageList2 = doDeepCopy(messageList);
  
  // Null out first copy
  messageList = null;

  doNetworkCall(messageList2)
}


Hopefully you see my intent -- null out the first list, hoping that clues the JVM in that it can reclaim that space. I just don't know if that has any meaningful effects -- I would think that the GC thread runs continuously, and by me removing the only live reference to that data it does now become a candidate for GC. I'm just wondering if I'm missing something.
Powered by LiveJournal.com
Image