Memory Leak: Deleting the Exception/Throwable Objects which are thrown from elsewhere

View: New views
2 Messages — Rating Filter:   Alert me  

Memory Leak: Deleting the Exception/Throwable Objects which are thrown from elsewhere

by abhi123 :: Rate this Message:

| View Threaded | Show Only this Message

This is my class
class ExceptionClass
{
        public void throwException() throws Exception
        {
                throw new Exception();
        }
}

And I have compiled its .class, .o and .h files
Now in my main I have included it <gcj/cni.h> and <ExceptionClass.h> also
    JvCreateJavaVM(NULL);
    JvAttachCurrentThread(NULL,NULL); in the begining and JvDetachCurrentThread(); in the end

Problem here is in I have a while loop which runs indefinitely and goes on creating
ExceptionClass objects and each invokes above throwException method. And everytime that method gets invoked a new Exception object is created which leads to memory leak because I am not able to delete it from main (or could say deleting doesn't help). How can I stabilize the memory utilization.

Thanks

Re: Memory Leak: Deleting the Exception/Throwable Objects which are thrown from elsewhere

by David Daney :: Rate this Message:

| View Threaded | Show Only this Message

abhi123 wrote:

> This is my class
> class ExceptionClass
> {
> public void throwException() throws Exception
> {
> throw new Exception();
> }
> }
>
> And I have compiled its .class, .o and .h files
> Now in my main I have included it <gcj/cni.h> and <ExceptionClass.h> also
>     JvCreateJavaVM(NULL);
>     JvAttachCurrentThread(NULL,NULL); in the begining and
> JvDetachCurrentThread(); in the end
>
> Problem here is in I have a while loop which runs indefinitely and goes on
> creating
> ExceptionClass objects and each invokes above throwException method. And
> everytime that method gets invoked a new Exception object is created which
> leads to memory leak because I am not able to delete it from main (or could
> say deleting doesn't help). How can I stabilize the memory utilization.

The libgcj runtime has a garbage collector.  There should be no problem.

If you can create a stand-alone testcase that shows a real problem, we
will try to fix it.

David Daney