GC cleans up object too early?


is clr bug or expected behavior?
have following c# code:

{
  someclass theobj = new someclass();

  theobj.dowork(); // note, may take several seconds return.
}

seeing theobj being disposed before call dowork returns.
if add call gc.keepalive(theobj) after dowork call, fine.
seems me should not necessary (it scares me because not sure how many other places in our code require call).

there details pertinent:
  • this x64 build (i haven't been able repro under win32)
  • the dowork method makes call unmanaged code, , in fact in unmanged code when dispose called.
  • someclass written in managed c++

brad pechacek



.NET Framework  >  Common Language Runtime Internals and Architecture



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'