Hi, I am leaving this post here both as a request for clarification, and in case someone may be having a similar issue, My game was crashing due to memory leak (partial logs below). In my game was constantly creating a temp Textures2D assuming that the GC would collect them, it wouldn’t, which wound up crashing due to lack of memory.
I solved it by simply storing a Texture and resizing it as necessary. My question here is why does the GC not collect it?
Unity Player [version: Unity 5.5.0f3_38b4efef76f0]
FullScreen.exe caused an Access Violation (0xc0000005)
in module FullScreen.exe at 0023:01551c50.
Error occurred at 2017-06-13_133126.
84% memory in use.
0 MB physical memory [931 MB free].
0 MB paging file [1657 MB free].
0 MB user address space [49 MB free].
Write to location 00000000 caused an access violation.
== [end of error.log] ==
Initialize engine version: 5.5.0f3 (38b4efef76f0)
.
.
.
DynamicHeapAllocator allocation probe 1 failed - Could not get memory for large allocation 524292.
DynamicHeapAllocator allocation probe 2 failed - Could not get memory for large allocation 524292.
DynamicHeapAllocator allocation probe 3 failed - Could not get memory for large allocation 524292.
DynamicHeapAllocator allocation probe 4 failed - Could not get memory for large allocation 524292.
DynamicHeapAllocator out of memory - Could not get memory for large allocation 524292!
Could not allocate memory: System out of memory!
Trying to allocate: 524292B with 16 alignment. MemoryLabel: Texture
Allocation happend at: Line:464 in
Memory overview
[ ALLOC_DEFAULT ] used: 24638484B | peak: 0B | reserved: 31719424B
[ ALLOC_TEMP_JOB ] used: 0B | peak: 0B | reserved: 20971520B
[ ALLOC_GFX ] used: 2864093380B | peak: 0B | reserved: 3683555300B
[ ALLOC_CACHEOBJECTS ] used: 221520B | peak: 0B | reserved: 10485760B
[ ALLOC_TYPETREE ] used: 0B | peak: 0B | reserved: 0B
[ ALLOC_PROFILER ] used: 0B | peak: 0B | reserved: 0B
[ ALLOC_TEMP_THREAD ] used: 32768B | peak: 0B | reserved: 3309568B
Could not allocate memory: System out of memory!
Trying to allocate: 524292B with 16 alignment. MemoryLabel: Texture
Allocation happend at: Line:464 in
Memory overview
[ ALLOC_DEFAULT ] used: 24638484B | peak: 0B | reserved: 31719424B
[ ALLOC_TEMP_JOB ] used: 0B | peak: 0B | reserved: 20971520B
[ ALLOC_GFX ] used: 2864093380B | peak: 0B | reserved: 3683555300B
[ ALLOC_CACHEOBJECTS ] used: 221520B | peak: 0B | reserved: 10485760B
[ ALLOC_TYPETREE ] used: 0B | peak: 0B | reserved: 0B
[ ALLOC_PROFILER ] used: 0B | peak: 0B | reserved: 0B
[ ALLOC_TEMP_THREAD ] used: 32768B | peak: 0B | reserved: 3309568B
(Filename: Line: 996)
Crash!!!
ERROR: Error while initializing dbghelp.dll, GetLastError: .’ (Address: 00000000)
========== OUTPUTING STACK TRACE ==================
ERROR: Error while initializing dbghelp.dll, GetLastError: ‘A operação foi concluída com êxito.’ (Address: 00000000)
========== END OF STACKTRACE ===========
**** Crash! ****
Textures also allocate memory outside of the managed Mono heap, and to free that memory you need to call one of the destroy functions (e.g. Object.Destroy(myTexture) or Object.DestroyImmediate(myTexture)) or call Resources.UnloadUnusedAssets() (this is slow though).
ina:
is this still true?
Yes by design. See @samizzo s response.