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()
2828
2929 if ( weakStream != null )
3030 {
31- return ( PooledBitStream ) weakStream ;
31+ PooledBitStream strongStream = ( PooledBitStream ) weakStream ;
32+
33+ strongStream . SetLength ( 0 ) ;
34+ strongStream . Position = 0 ;
35+
36+ return strongStream ;
3237 }
3338 }
3439
@@ -44,6 +49,7 @@ public static PooledBitStream GetStream()
4449 }
4550
4651 PooledBitStream stream = streams . Dequeue ( ) ;
52+
4753 stream . SetLength ( 0 ) ;
4854 stream . Position = 0 ;
4955
@@ -58,10 +64,10 @@ public static void PutBackInPool(PooledBitStream stream)
5864 {
5965 if ( streams . Count > 16 )
6066 {
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
6571 if ( LogHelper . CurrentLogLevel <= LogLevel . Developer ) LogHelper . LogInfo ( "Putting PooledBitStream into overflow pool. Did you forget to dispose?" ) ;
6672 overflowStreams . Enqueue ( new WeakReference ( stream ) ) ;
6773 }
You can’t perform that action at this time.
0 commit comments