Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I originally posted this question on StackOverflow but was told to move it here.

I have an application that I have been developing for the last two years, and over the course of time it has become increasingly complex. At it’s core is a tree structure where each node corresponds to a level in my application with certain properties. At the leaf nodes there are more properties than in the intermediate nodes. When I started developing this app I made the tree structure as an object with a list of children objects of same type, with the possibility of extending the leaf nodes.

Gradually more and more features and thus properties have been implemented, and I have found that creating objects for all my features and properties is taking quite a bit memory. From the beginning I did not consider using a database, and such the application is in no way structured to use a database. The application reads data from files, and can thus vary in memory usage according to the size of the file loaded. For a small file loaded the app uses roughly 300K objects and has allocated about 16 MB. For larger files it can use upwards of 500K - 600K objects and allocate all it’s availabe memory.

My problem is that I am going to extend the application further in the future, while the files being loaded becomes bigger and bigger. What is the way to go? Should I completely restructure the app to use databases and will it be quick? Should I continue using objects and just assume that devices are becoming increasingly potent and can handle all my objects? Can I do some sort of crossover, keeping my tree structure and basic objects and moving other stuff to databases?

share|improve this question
I know you were told to come here, but this is clearly not a code review question. – Winston Ewert Jun 6 '12 at 5:30

closed as off topic by Winston Ewert Jun 6 '12 at 5:30

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

Do you have to load your file fully? What is the kind of usage profile that you have with your application? That is, if you are going to use a particular node,

  • Do you have use its siblings more
  • Or do you use all its children or only a particular path?
  • Is your usage predictable? That is, given one node is needed, can you predict the usage for the next needed nodes for at least some of the time?

I would recommend two different approaches if some of the above match

  • Load the tree lazily, and garbage collect those nodes that have not been in use
  • Load a skeleton tree, and use a cache as store of objects. Load objects from this cache as needed, and let the cache keep its objects in an MRU policy. This way, only those objects that are often used would be stored in the memory.
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.