advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   TIP BANK
Browse DevX
Partners & Affiliates
advertisement
advertisement
Tip of the Day
Expertise: Intermediate
Language: Java
September 30, 1999
Lazy Versus Eager Instantiation
There are techniques for creation of objects (read allocation of memory) widely known as lazy Instantiation and Eager Instantiation.
Lazy instantiation is a memory conservation technique, by which, a program delays the creation of objects until those objects are needed. In Java, there are two categories of lazy instantiation:

1. Lazy class loading
The Java runtime loads classes into memory only when they're first referenced. This may happen due to a first call to a static method of a class as in:

 
aClass.someStaticMethod();
or a first call to the "new" operator to create an instatnce of a class as in:
 
AClass aClass = new AClass();
This is a very important feature of the Java runtime. Memory usage can be significantly reduced. For example, if a part of a program is never run, classes that are only referenced by that part of the program will never be loaded.

It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com.
Already a member?





Behrouz Fallahi
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.
advertisement
advertisement