It depends on your configurations, since HotSpot is configured differently in different Java environments. For example, on a server with more than 2 GB and two processors, some JVMs will be configured in the "-server" mode instead of the "-client default" mode, which adjusts the sizes of memory spaces (generations) in different ways, and the effect on when it happens garbage collection.
A full GC can happen automatically, but also if you call the garbage collector in your code (for example: using System.gc() ). Automatically, it depends on how small collections behave.
At least two algorithms are used. If you use the default values, the copy algorithm is used for small collections, and the markup algorithm is used for main collections.
The copy algorithm consists in copying the used memory from one block to another, and then clearing the space containing the blocks, without reference to them. The JVM copy algorithm uses a large area for objects created for the first time (called Eden ) and two smaller ones (called survivors ). Surviving objects are copied once from Eden and several times from survivor spaces during each junior collection until they are hired and copied to another space (called tenured space), where they can only be deleted in the main collection.
Most objects in Eden die quickly, so the first collection copies the remaining objects to the remaining spaces (which are much smaller by default). There are two survivors s1 and s2 . Each time Eden filled, the preserved objects from Eden and s1 copied to s2 , Eden and s1 are cleared. Next time, survivors from Eden and s2 will be copied to s1 . They continue to be copied from s1 to s2 to s1 until a certain number of copies are reached, or because the block is too large and not suitable, or some other criteria. Then the saved block of memory is copied to the generation of tenured .
tenured objects do not affect secondary collections. They accumulate until the area is full (or the garbage collector is called). Then the JVM will run the markup algorithm in the main collection, which will save only the preserved objects that still have links.
If you have larger objects that are not suitable for survivors, they can be copied directly to the tenured space, which will fill up faster, and you will get larger collections more often.
In addition, the size of the remaining living spaces, the number of copies between the sizes s1 and s2 , Eden , related to the size s1 and s2 , the size of the generation generation, all this can be automatically adjusted differently in different environments with JVM ergonomics, which can automatically choose behavior -server or -client . You can try to run both JVMs as -server or -client and check if they all behave differently.