App hangs, GC.collect() fixet it. Why?

Steven Schveighoffer schveiguy at gmail.com
Fri Jun 5 21:20:09 UTC 2020


On 6/5/20 1:57 PM, Bastiaan Veelo wrote:
> I've been tracking down a hang in our pilot app. Using writeln, it 
> appears to hang at newing a slice. After many hours of trying things, I 
> discovered that program flow would continue past that point when I 
> inserted a call to `GC.collect()` just before. Then it stalled again at 
> a call to Win32 `SetMenu()`. Again, inserting `GC.collect()` before that 
> made the problem go away.
> 
> This band-aid isn't going to scale in the long run. I feel I'm treating 
> symptoms, and wonder what the cause is. Any ideas?
> 
> I know the GC is not disabled somehow because if I print 
> `GC.profileStats()`, I see that there are collections even without my 
> explicit calls to `GC.collect()`.

1. collections happen automatically when you allocate memory and it 
can't find any free memory to allocate with.
2. Even if it can't find any free memory after a collection, and it runs 
out of memory, it should throw an Error instead of hanging.

The only thing I can think of is to open in a debugger and see what it 
is doing.

This kind of sounds like a codegen bug, a race condition, or (worst 
case) memory corruption.

-Steve


More information about the Digitalmars-d-learn mailing list