Skip to main content

Posts

Showing posts from October, 2015

Optimization through WeakReference

WeakReference is a new element added into 4.5 framework, but it was available in Java from the earlier stage only. So, this article could be useful for .Net, Java, and Android as well.

What is it?
It is nothing more than a class but what special about is to interact with Garbage Collector in a certain way which could help out in optimization.

Scenario
We all know that static members are created and shared throughout the application and life cycle by maintaining only single instance. Possibly it can useful in cases where data need to be frequently accessed but what about those that doesn't need to be frequently accessed all times. Those data might be resource hungry data so static or some kind of caching mechanism is required. Storing something in static members or caching increases memory footprint for the application. This is once situation, but there might be other situation as well.
WeekReference is a technique to hook up member with Garbage collector to retrieve actual object i…