Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
My technical lead claims that throwing an exception from a constructor in Java may leave allocated memory that is not cleaned up and that we should do very little in a constructor and avoid throwing exceptions. I believe this to be wrong but could not find any definition of what happens to the allocated memory when the initialization of a class is interrupted by throwing an exception. Anyone know what the answer is? I prefer not having a two step process to initialize an object because then I have to put in initialization check in all the functions. Also, what is the value of a reference variable when initialzation is interupted? Does Java set it to null or just leave it what it was before? If it is the second, then I suppose that the reference could still be pointing to a valid object; assuming it was pointing to one before the attempt to initialize the new object: Replies: |
Sponsored Links
|