Monday, March 1, 2010

Heap issue with Ant Task

Long time ago i had seen the following error message after running ant task for my project.

[java] Error occurred during initialization of VM
[java] Could not reserve enough space for object heap
[java] Could not create the Java virtual machine.

I had connected to my development server via a remote desktop from Windows. I have a 2 gig ram on my server and I felt because i was doing remote desktop there was insufficient memory for the ant task. Hence i tried using VNC viewer and guess what the error was no longer to be seen. However a new sort of problem or should i say frustration came along with VNC viewer. First i had to disconnect my remote desktop session and then connect in via vnc. However this would require atleast 15-20 frustrating attempts cause most of the times VNC would fail to connect saying Connection terminated by the host. After living with this frustration for some time , i finally decided i had it enough and decided to get a solution to my original problem of insufficient heap.

The portion of my ant script that was throwing the error is
classname="com.buildextensions.web.TomcatBootstrap"
failonerror="true"
fork="true"
dir="@{dir}"
maxmemory="1000m">

The ant task i have here forks a VM for TomcatBootstrap. So if you see maxmemory was set to 1000m. At first i thought of setting it to 1500m , 2000m and 3000m and it did not help. The maxmemory field is the maximum amount of memory to allocate to the forked VM, the more you allocate the lesser heap will be left. Hence you would see insufficient heap, hence one should allocate only the required minimum heap to the forked ant. Thus reducing maxmemory to 200m solved the problem. No more woes with VNC viwer, i can now use remote desktop to run the project and spend some more time blogging. As they say "Less is more".

No comments:

Post a Comment

Twitter Updates

    follow me on Twitter