× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



or even remove references early by setting them to null.

Assuming the JVM GC is roughly as smart as the CLR's GC, setting the
reference to null is an unnecessary step. An object is eligible for
collection when it can no longer be referenced... it doesn't actually
need to be out of scope yet.

The GC can tell that an object won't be referenced any longer and clean
it up even if you still hold a reference to it, provided you never use
that reference again in your code. IOW, the compiler/JIT does much of
that 'set to null' optimization for you. For example:

1 public int SomeFunction()
2 {
3 SomeClass newObject = new SomeClass();
4 OtherClass otherObject = new OtherClass();
5 int x = 22;
6 SomeFunction(newObject);
7 for (int i=0;i<x;i++)
8 {
9 OtherFunction(otherObject);
10 }
11 ThirdFunction(x);
12 FourthFunction(otherObject);
13 }


Reason would say that newObject can be collected at the end of the
method (line 13), but at least in the CLR's GC it can be collected after
line 6. I would assume the JVM's GC has similar optimizations.

-Walden


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.