Description:
Memory doesn't get freed or objects are not cleaned up by the automatic garbage collector at runtime.
How to repeat:
# The following is part of the unittests for creating the fix
class BugGarbage(tests.MySQLConnectorTests):
def setUp(self):
self.sample_size = 4
self._reset_samples()
gc.collect()
def _reset_samples(self):
self.samples = [0,] * self.sample_size
def _assert_flat_line(self, samples):
for i in range(0, len(samples)-1):
try:
if samples[i] != samples[i+1]:
self.fail("No flat-line for number of collected objects")
except IndexError:
pass # We are at the end.
def test_cursor(self):
config = self.getMySQLConfig()
cnx = connection.MySQLConnection(**config)
# Create a cursor and close using close()-method
for i in range(0, self.sample_size):
cursor = cnx.cursor()
cursor.close()
self.samples[i] = len(gc.get_objects())
self._assert_flat_line(self.samples)
self._reset_samples()
# Create a cursor and rely on destructor to close
for i in range(0, self.sample_size):
cursor = cnx.cursor()
self.samples[i] = len(gc.get_objects())
self._assert_flat_line(self.samples)