File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -467,6 +467,25 @@ def sizes():
467467 self .assertEqual (f .read (100 ), b'' )
468468 self .assertEqual (nread , len (uncompressed ))
469469
470+ def test_no_refloop_with_writestream (self ):
471+ """Test that the _WriteBufferStream __del__ method prevents reference loops."""
472+ import gc
473+
474+ gc .collect ()
475+
476+ before_count = len (gc .get_objects ())
477+
478+ with io .BytesIO () as bio :
479+ with gzip .GzipFile (fileobj = bio , mode = "wb" ) as f :
480+ f .write (b"test data" )
481+
482+ gc .collect (0 )
483+
484+ # Check that all objects were properly cleaned up
485+ after_count = len (gc .get_objects ())
486+ self .assertLess (after_count - before_count , 10 ,
487+ "Too many objects remain after GzipFile cleanup" )
488+
470489 def test_textio_readlines (self ):
471490 # Issue #10791: TextIOWrapper.readlines() fails when wrapping GzipFile.
472491 lines = (data1 * 50 ).decode ("ascii" ).splitlines (keepends = True )
You can’t perform that action at this time.
0 commit comments