Question: I have a requirement to store user ids appending with numbers like:

If user id is "stackoverflow", then first 7 letters of id "stackov" is taken and if it not there in the DataBase then it should be stored as "stackov001".

Now if another user gives similar user id as "stackoverflowed" then its user id should be stored as "stackov002" because 

I tried this by using substring but i am not able to get "00". I am able to get "stackov1" "stackov2" but not "stackov001".

Can soemone please help on this.

Answer: 
`XmxSIZE` can be greater then Java core dump because `OutOfMemory` happen when you try to allocate a large object!

Our application with `-Xmx1000m` and 670 MiB dump crashed by `OutOfMemory` on uploading 300 MiB attachment by a user.

We discover this in VisualVM in "Show Threads" trace on `System.arrayCopy`. Reference from local stack frame variable point to 300 MiB byte array.

Now we limit attachment size and save our application from future crashes.
**First** you need to take a look at the following memory parameters, it may not prevent the `OutOfMemoryError`, but you should learn about them:

```
-Xmx2048m -> this param to set the max memory that the JVM can allocate
-Xms1024m -> the init memory that JVM will allocate on the start up
-XX:MaxPermSize=512M -> this for the max Permanent Generation memory

```

Also and you may want to check this parameters also, those parameters will speed up the `GC` activities on your Young space, so the collection will be better.

```
-XX:MaxNewSize=  -> this need to be 40% from your Xmx value
-XX:NewSize=614m -> this need to be 40% from your Xmx value

```

also you may tell you `JVM` what type of `GC` to use like (i think this type is already enabled in the newest `JVM` versions) :

```
-XX:+UseConcMarkSweepGC

```

**Second**

When an `OutOfMemoryError` occured, the `JVM` will trigger the `Stop World GC`, so it will collect your object and the un referenced object, that why the heap size is less than you `-Xmx` value.

Usually in this case, if you analyzed this heap using one of the analyzing tools, you will clearly find the big objects that filled your memory, that will led you to the code and it will be easy to fix it.