Bloomberg LP Interview Question
Financial Software DevelopersCountry: United States
Interview Type: Phone Interview
1. Reference Counting for each object. Deletion is triggered when counters reach down to 0
2. Periodically check all heap objects. Deletion is triggered if there is some object which has no reference pointing to.
There is some naive idea to implement 2) in a way of customization.
a) customize or overload new operator such that all used heap addresses are stored in @HeapObjects.
b) customize a new reference/pointer class such that all references are stored in @References.
c) delete (HeapObjects - References) set of objects.
Triggers for 2) is arguable. Some designs except peridoic checking are setting upper bound of used heap, etc. (not much from at top of my head)
There are many ways to implement this in C++
- hprem991 February 06, 2013Basically it runs on the algo where you need to make sure the Object in Context is having any reference or not.
One simple implementation uses something called a Counter Class which basically Counts the number of reference to a particular object. So when the reference becomes 0, it deallocates the memory.
Another and more prominent way uses something more in complex algo. This is a daemon that is schedule to run periodic to check the object is in the state of removal or not and for every such check it increments the counter. Actually this algo is beyond the scope of discussion here but being real time implemented in case of JVM Garbage Collector.