Compilation OutOfMemoryError !!!

stefanoa

Active Member
Licensed User
Longtime User
.....
Generating R file. 0.00
Compiling generated Java code. 5.07
Convert byte code - optimized dex. Error
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2760)
at java.util.Arrays.copyOf(Arrays.java:2734)
........

what's the problem??? :sign0085:
thanks
 

SiriusCG

Member
Licensed User
Longtime User
There are a few possibilities but the most common is creating an array that is too large for the heap space (allocated memory) to contain.

You can do a couple of things: check your code to make sure your arrays aren't bigger than you need and that your code is correct. If your code is correct or you can't change it, about the only other thing you can do is increase the heap space:

Start the application with the command line switch: -XmxSizeUnits

for example:
To set a max heap size of 128Mb use: java -Xmx128m
To set a max heap size of 640kb use: java -Xmx640k

I'm new to B4A, so I don't know yet how to change the java compiler directives from inside the IDE. Perhaps someone else can provide that info ..

Cheers
 
Last edited:
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
thanks...
but the code is correct..
i've to know how modify those parameters in B4A IDE.

I have about 46 modules in my projects... if I delete some module... it works!

please help
thanks
 
Upvote 0

SiriusCG

Member
Licensed User
Longtime User
You may need to refactor some of your code. I've had to do this many times when creating large C/C++ projects. Is there anywhere where you can refactor your code to make it more efficient?

Or, you're simply running out of memory when you try to compile all the modules at the same time. Try to reduce the number of other applications you might have running when you compile to free up memory. Splitting up your code so you don't compile all the modules at the same time might be an alternative.

Cheers.
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
all modules are of the same project and must be compiled in the same apk...
the error occurs when i try to compile..
 
Upvote 0

SiriusCG

Member
Licensed User
Longtime User
There are a few of possibilities:

1. You have code in a another module that's causing the problem. In that case, you'll need to find the offending module and possibly refactor or recode it. You mentioned the project compiles if you reduce the number of modules. You may have some offending code in one of those you removed previously and it's halting compilation.
2. Reduce the actual number of modules by relocating code. Perhaps you can reduce the number of modules by moving code around and redistributing it.
3. There may be a limit on the number of modules that can be compiled for a particular project. I don't know if this is true, just putting it out there.

Cheers.
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
if i compile with "release" method, the compilation is ok but is very slow..
the error OutOfMemoryError occurs when i try to compile with "debug" method..
it's very difficult to combine different modules because they have different layouts..
 
Upvote 0

SiriusCG

Member
Licensed User
Longtime User
I wouldn't be surprised about the memory issue when compiling with debug. It adds a lot of information to the compiled modules. It would be easy to run out of memory when compiling this way ...

There's not much more I can add other than what I've already suggested. Large programs take a lot of resources. Unless you tweak the compiler memory parameters, add more physical memory perhaps to your computer or refactor your code to make it more efficient, I think you're stuck with slow compilation and no option to debug ...

Cheers.
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
ok...
for now I solved by setting the value MaxRamForDex in file b4aV0.1.ini

from:
MaxRamForDex=512

to:
MaxRamForDex=1024

thanks !!!
 
Upvote 0

cbal03

Member
Licensed User
Longtime User
Debug Compilation OutOfMemoryError

I am also running into this problem. I have begun to use the newest version 2.5 and still I have debug mode compilation problems. I can however compile normally.
 
Upvote 0

cbal03

Member
Licensed User
Longtime User
Thank you Erel. I'll do that. Great new release!

The change from 512 to 1024 worked nicely.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…