jack-pappas / ExtCore

An extended core library for F#.
Apache License 2.0
178 stars 32 forks source link

Make sure enumerators are always disposed #16

Closed jack-pappas closed 9 years ago

jack-pappas commented 9 years ago

A number of ExtCore functions, e.g., those in the Seq module, call GetEnumerator() on a seq<'T> but don't dispose the resulting enumerator. This is a problem, because the enumerator can (for example) hold handles to unmanaged resources, which are leaked when the enumerator isn't disposed properly.

The first step to fixing these issues will be to implement a custom IEnumerable<T> type in ExtCore.Tests; when GetEnumerator() is called on this type, it should return an instance of IEnumerator<T> that captures a ref cell stored inside the parent and is incremented when GetEnumerator() is called and decremented when the enumerator is disposed. This way, unit tests can assert that allocated enumerators have been disposed.

jack-pappas commented 9 years ago

These tests have been implemented and the affected functions have been fixed to dispose the enumerators they create.