Question: I am getting
"OutOfMemoryError". How do I prevent such memory leaks?
Answer: It is not always a memory leak that
A memory leak is a situation when some application, for example JVM allocates
some amount of memory and then loses pointers to that area. So, the allocated
area becomes a "black box" which you can not access and you need a key to open
It is very rare situation when some Java code causes memory leaks.
They are reported and can be found at "Bug parade" on SUN's web site.
"OutOfMemoryError" often caused by bad design. It can be for example:
1. Your program trying to process too much data. Increase the amount of memory
or decrease the amount of data to be processed.
Actually you can do it in a wise way: control how much memory left and if it
less than, let say 20 %, decrease the processing speed.
It was described in one of our tips while ago...
2. Your program holding too many objects and then program is running out of
You need to use close methods if you do need them. You can even explicitly set a
reference to null to speed up garbage collection.
3. You use too many objects with finalizers... They consume your memory before
you get any chance to run them...
Question: Are any classes available to
deal with Mac Address ( not IP ) and which are these classes?
Answer: Java deals at the higher level with
protocol TCP/IP (layers 4/3). Mac address is used in layer 2 by Ethernet.
Although you can work with them if you use ARP, RARP (Address Resolution
Protocol and Reverse Address Resolution Protocol) and some native code...
Our older tips: March 22, 2001 - October 21, 2002
All published and not published on the site tips you can find