• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Memory Allocation for Multi-nomial Tree Recursion

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm experiencing an OutofMemoryError exception while recursing through a tree with a large number of branches (30) but relatively small depth (5). Here's the basic idea of the code:

I start growing the tree using a depth-first method, and after I reach the leaf node, I assign a value to the node and then recursively calculate the value of the their parent node with some formula. Ideally I hope Java's garbage collector can recycle all the memory of all the child nodes once I get the value of the parent node, as I won't have any use of them. So according to that I only need to store at most 30 * 5 nodes in the memory at any time. However apparently that is not the case, and could someone please let me know how I can recycle the memory for the recursion?

thanks,
Colin
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Colin:
Ideally I hope Java's garbage collector can recycle all the memory of all the child nodes once I get the value of the parent node, as I won't have any use of them.


Garbage collector will only collect the memory if it can not be reached strongly from anywhere in your program.
If you are getting an OutOfMemory error then be assured that either you actually do not have enough memory to run the entire program or you are holding on to the references that are no longer required.
 
Ranch Hand
Posts: 376
Scala Monad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using recursion, the problem could be also the stack size. I found that with even "simple" recursions, I run out of memory pretty quick.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic