Thursday, February 11, 2010

New operator is like growing Population !!!

Long back before 3 idiot movie of course even before five point some one. We must have realized life in india is a race. For every stupid thing staring from local bus to admission in higher studies and getting a job is challenging here. Why we have such a situation. The answer is pretty simple we are more than 1000 million people country. And we have not sufficient resource to handle it. Definitely I don't want to advocate here some family planning program or how to stop population growth. All of us know the solution for it. Only we need to use our operators carefully !!!
In our computer world the resource is keep increasing. The computers are faster it has more memory. Still I face the respect full errors like java.lang.OutOfMemory error. I was thinking how can I stop population i mean object population so that they don't have to race for memory,cpu etc. They can have a healthy life cycle.... I checked my code I found 99.9 % time I use new operator to create object ( 1% is the interview tips, we can create object using reflection api and Class.for ...) .
If I can use some kind of protection on new operator things will work .....
Then like conservative use new operator when its really required. You have no other object available to do the job.  then only create the object otherwise reuse the existing one .
Avoid new in Loop.  Less object Light application... Happy Users...

No comments:

Post a Comment