Thursday, June 05, 2008

Thread local storage leak in Compact CLR

Its pretty easy to use thread local storage on the CLR using the LocalDataStoreSlot and the Thread.Get/SetData methods. The unfortunate part is that the LocalDataStore is not freed after the thread dies .(LocalDataStore is essentially the per-thread data store which is created the first time something is set in the thread storage).

This is a big issue as memory is short on devices and apps which use threadpool to process their work items (using TLS) will end up leaking a lot as thread pool keeps spawning/exiting threads based on load.

Update: this is an issue only with netcf 2.0, it has been fixed in netcf 3.5

No comments: