File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
MLAPI/Serialization/Pooled Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,12 @@ public static PooledBitStream GetStream()
28
28
29
29
if ( weakStream != null )
30
30
{
31
- return ( PooledBitStream ) weakStream ;
31
+ PooledBitStream strongStream = ( PooledBitStream ) weakStream ;
32
+
33
+ strongStream . SetLength ( 0 ) ;
34
+ strongStream . Position = 0 ;
35
+
36
+ return strongStream ;
32
37
}
33
38
}
34
39
@@ -44,6 +49,7 @@ public static PooledBitStream GetStream()
44
49
}
45
50
46
51
PooledBitStream stream = streams . Dequeue ( ) ;
52
+
47
53
stream . SetLength ( 0 ) ;
48
54
stream . Position = 0 ;
49
55
@@ -58,10 +64,10 @@ public static void PutBackInPool(PooledBitStream stream)
58
64
{
59
65
if ( streams . Count > 16 )
60
66
{
61
- //The user just created lots of streams without returning them in between.
62
- //Streams are essentially byte array wrappers. This is valuable memory.
63
- //Thus we put this stream as a weak reference incase of another burst
64
- //But still leave it to GC
67
+ // The user just created lots of streams without returning them in between.
68
+ // Streams are essentially byte array wrappers. This is valuable memory.
69
+ // Thus we put this stream as a weak reference incase of another burst
70
+ // But still leave it to GC
65
71
if ( LogHelper . CurrentLogLevel <= LogLevel . Developer ) LogHelper . LogInfo ( "Putting PooledBitStream into overflow pool. Did you forget to dispose?" ) ;
66
72
overflowStreams . Enqueue ( new WeakReference ( stream ) ) ;
67
73
}
You can’t perform that action at this time.
0 commit comments