diff --git a/runtime/src/main/cpp/Memory.cpp b/runtime/src/main/cpp/Memory.cpp index 4affb85b435..4f6e836a65e 100644 --- a/runtime/src/main/cpp/Memory.cpp +++ b/runtime/src/main/cpp/Memory.cpp @@ -688,7 +688,8 @@ ContainerHeader* allocContainer(MemoryState* state, size_t size) { #endif if (result == nullptr) { #if USE_GC - state->allocSinceLastGc += size; + if (state != nullptr) + state->allocSinceLastGc += size; #endif result = konanConstructSizedInstance(alignUp(size, kObjectAlignment)); atomicAdd(&allocCount, 1); @@ -1661,7 +1662,7 @@ void updateHeapRefIfNull(ObjHeader** location, const ObjHeader* object) { } inline void checkIfGcNeeded(MemoryState* state) { - if (state->allocSinceLastGc > state->allocSinceLastGcThreshold) { + if (state != nullptr && state->allocSinceLastGc > state->allocSinceLastGcThreshold) { // To avoid GC trashing check that at least 10ms passed since last GC. if (konan::getTimeMicros() - state->lastGcTimestamp > 10 * 1000) { garbageCollect(state, false);