How to Remove Unused Objects in Eclipse?

时间:2019-04-17 01:37:48

标签: java eclipse ide

I'm working on a project for several years now and I found that I declare thousands of objects in various classes that are never used locally such as:

public class MyClass {


 ClassA classA = new ClassA();
 ClassB classB = new ClassB();
 ClassC classC = new ClassC();


 public void performAction()
 {
 classA.doA();
 }


}

While I use instance of classA in MyClass I never use classB and classC locally (they're used in other classes of course). Of course, this is just one example. My project has several thousand instances of classes (spread across hundreds of classes) that are never used. Apparently, I thought I'd actually need access to the methods in classB and classC but never actually did and I'm left with thousands of unnecessary object instantiations. I believe this is causing a significant increase in memory utilization (correct?).

Is there a way to automatically detect instances of unused classes and delete them in Eclipse? I know there's a way to delete unused imports but I could not find anything on SO about unused objects.

I'm using Eclipse Version: Mars.2 Release (4.5.2)

Thanks!

0 个答案:

没有答案
相关问题