Using blocks to limit the scope of variables inside lengthy(taking long operation time) functions, to free up heap quickly
I am using Java for a web application. To free up heap of the unneccesary variables objects, is it a better strategy to Using blocks to limit the scope of variables inside lengthy(taking long operation time) functions and thus free up space as quickly as possible ?
I understand splitting methods into smaller ones is a good idea, but even after that I feel the need to use blocks in those smaller functions.
I wou开发者_Python百科ld use several blocks inside a single functions so that whenever the job of a variable is over is gets out of the scope and garbage collector can clean the space as quick as possible
That should work, but if those blocks can be identified as mostly independent from each other it should be possible to find a name which describes their duty and make them separate methods.
Smaller methods are more easy to reason about, and it is more easy to test their code in a testing framework.
精彩评论