Opened 10 years ago
Closed 10 years ago
#13817 closed defect (fixed)
Memory leak in python vboxapi
Reported by: | ali123 | Owned by: | |
---|---|---|---|
Component: | other | Version: | VirtualBox 4.3.20 |
Keywords: | vboxapi python sdk | Cc: | |
Guest type: | all | Host type: | Windows |
Description
This is an issue with the python library in the sdk: sdk/install/vboxapi/__init__.py
If you create, then delete, a WEBSERVICE VirtualBoxManager object then it leaves 2 uncollectable objects in the garbage collector: vboxapi.VirtualBoxManager and ZSI.parse.ParsedSoap. The first is due to a circular reference, and the second due to a typo.
To replicate:
import gc from vboxapi import VirtualBoxManager creds = {'url': 'http://SERVER:18083', 'user': 'USERNAME', 'password': 'PASSWORD'} manager = VirtualBoxManager('WEBSERVICE', creds) del manager gc.collect() gc.garbage
This displays the uncollectable objects:
[<vboxapi.VirtualBoxManager object at 0x0235DED0>, <ZSI.parse.ParsedSoap instance at 0x0413D7D8>]
To workaround: Perform the following instead of "del manager":
manager.platform.disconnect() del manager.mgr del manager
The circular reference issue:
__init__.py
has a circular reference at the end of the __init__
method of the VirtualBoxManager class (line 996):
self.mgr = self;
The VirtualBoxManager class also defines a __del__
method (line 998).
A circular reference and a __del__
method mean that the object cannot be collected by the garbage collector (see https://docs.python.org/2/library/gc.html#gc.garbage).
The typo:
In file __init__.py
, class PlatformWEBSERVICE, method deinit it calls disconnect(), where it should call self.disconnect() (line 878).
Change History (5)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Hopefully fixed SDK package is at https://www.virtualbox.org/download/testcase/VirtualBoxSDK-4.3.21-98155.zip - feedback is very welcome.
comment:4 by , 10 years ago
Thanks for the quick feedback... will be included in the next 4.3 release.
Thanks for letting us know... the circular reference was trivially replaced by a property and the rest you already served on the silver platter. Will try to wrap this up ASAP and pass you a new SDK package for testing.