Skip to content

Commit

Permalink
Better disposing behavior of cursor.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanwin committed May 14, 2010
1 parent ce20f4b commit 54bd94b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions source/MongoDB/Cursor_1.cs
Expand Up @@ -59,6 +59,14 @@ public Cursor(ISerializationFactory serializationFactory, Connection connection,
_limit = limit;
_skip = skip;
_fields = fields;
}

/// <summary>
/// Releases unmanaged resources and performs other cleanup operations before the
/// <see cref="Cursor&lt;T&gt;"/> is reclaimed by garbage collection.
/// </summary>
~Cursor(){
Dispose(false);
}

/// <summary>
Expand Down Expand Up @@ -238,15 +246,25 @@ public int CursorPosition

return _reply.StartingFrom + _reply.NumberReturned;
}
}

}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
if(Id == 0)
return; //All server side resources disposed of.
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if(Id == 0) //All server side resources disposed of.
return;

KillCursor(Id);
}
Expand Down

0 comments on commit 54bd94b

Please sign in to comment.