ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1439. Battle with You-Know-Who

Memory Limit error with less then 5MB allocated to program
Posted by VC67 8 May 2011 15:36
I'm have gotten "memory limit exceeded" on test 2. I try to solve this task with Fenwick tree in Java.
But "memory allocated" value in result table is only 4.7MB. Stated memory limit is 16MB, and some of accepted solution have almost 16MB allocated (ID 3136829 for example).




Edited by author 08.05.2011 15:37
Re: Memory Limit error with less then 5MB allocated to program
Posted by VC67 8 May 2011 17:10
It seems that if programm tries to allocate real big chunk of memory, that does not show in result table. i.e. 5MB and 2 test is state of program before its attempt to allocate too many mem.
Re: Memory Limit error with less then 5MB allocated to program
Posted by AterLux 8 May 2011 19:19
It's Java Memory Model.
On this server Java runs with minimal and maximal size of heap sets to 64 Mb.
When you creating new Java objects it allocated in heap and still there until garbage collection, even if you not using it. Since your program make calculations and not idle, Garbage collector can't collect in background an will run when most of memory will occuped
So, avoid to create multiple objects with short life-time, be carefull with explicit-created objects
For exapmle Scanner.nextInt explicit creating String object, that then converted into the integer, but String and associated char-array remains in memory.
Also any String you created (for example when reading from file) are remain in heap until the garbage collection: when reading from file use byte-by-byte reading, char reading instead of Scanners Strings and other