File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Runtime . ConstrainedExecution ;
4+ using System . Runtime . InteropServices ;
5+ using System . Text ;
6+
7+ namespace Imageflow . Net . Bindings
8+ {
9+ internal class PinBox : CriticalFinalizerObject , IDisposable
10+ {
11+ private List < GCHandle > _pinned ;
12+ internal void AddPinnedData ( GCHandle handle )
13+ {
14+ if ( _pinned == null ) _pinned = new List < GCHandle > ( ) ;
15+ _pinned . Add ( handle ) ;
16+ }
17+
18+ public void Dispose ( )
19+ {
20+ UnpinAll ( ) ;
21+ GC . SuppressFinalize ( this ) ;
22+ }
23+
24+ private void UnpinAll ( )
25+ {
26+ //Unpin GCHandles
27+ if ( _pinned != null )
28+ {
29+ foreach ( var active in _pinned )
30+ {
31+ if ( active . IsAllocated ) active . Free ( ) ;
32+ }
33+ _pinned = null ;
34+ }
35+ }
36+
37+ ~ PinBox ( )
38+ {
39+ UnpinAll ( ) ;
40+ }
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments