Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#9262 closed (invalid)

Memory leak in django.utils.version.get_svn_revision

Reported by: Ilya Semenov Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


django.utils.version.get_svn_revision suffers from a memory leak: it opens a file without closing it. I'm attaching the trivial patch.

Attachments (1)

9107.patch (628 bytes) - added by Ilya Semenov 10 years ago.

Download all attachments as: .zip

Change History (5)

Changed 10 years ago by Ilya Semenov

Attachment: 9107.patch added

comment:1 Changed 10 years ago by Daniel Pope <dan@…>

Resolution: invalid
Status: newclosed

Python files are automatically closed when the reference count drops to zero, which happens immediately in this case.

For example:

>>> import os
>>> f = open('foo')
>>> f.fileno()
>>> os.fstat(3)
(33188, 4672869, 65024L, 1, 1000, 1000, 5111, 1222865095, 1217326625, 1217326625)
>>> del f
>>> os.fstat(3) 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 9] Bad file descriptor

comment:2 Changed 10 years ago by mrts

Resolution: invalid
Status: closedreopened

You can't assume CPython refcounting now that Django runs officially on Jython.

Quote from

Jython has "true" garbage collection whereas CPython uses reference counting. This means that in Jython users don't need to worry about handling circular references as these are guaranteed to be collected properly. On the other hand, users of Jython have no guarantees of when an object will be finalized -- this can cause problems for people who use open("foo", 'r').read() excessively. Both behaviors are acceptable -- and highly unlikely to change.

comment:3 Changed 10 years ago by James Bennett

Resolution: invalid
Status: reopenedclosed

"no guarantees of when an object will be finalized" != "object will never be finalized". If we were opening thousands of files and never explicitly closing them, there might be a case for changes (since they might not get auto-collected soon enough), but that's not what's happening, so let it rest.

comment:4 Changed 10 years ago by Ilya Semenov

I am the topic starter and I agree with closing the ticket as invalid. I was reported about the memory leak by our team profiling results and didn't check myself if it actually took place (my bad).

Note: See TracTickets for help on using tickets.
Back to Top