I was trying to make a web application with lots of JS code fast & efficient.
There are some dynamic objects which collect data in a loop and then are looped over to display somewhere else.
I explicitly set all these objects to null after their corresponding displaying loop has been terminated like:
loop executed over tempCatObj tempCatObj = null; //after the loop is over
On using Memory tab of Chrome Developer tools,I noticed the heap size now shows more than the case before.
Head SnapShot(using Chrome Developer Tool)(profile A) without setting null: 7.8 MB After setting to null : 8 MB
Another profiling(profile B):
On Sampling Allocation Profile(stats of a custom function formDisplayGrid inside which the objects were set to null) without setting null: 279048 bytes 58.56% After setting to null : 98520 bytes 31.54%
both these results seem to be contradicting each other.
I was expecting profile A to show smaller data size in case of objects being set to null as that seems to be freeing up space which seem to be happening in profile B.
An assumption was also that setting dynamic objects would be helpful for the Garbage Collector to clean up.
Is this the correct way of analysis?