Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#9262 closed (invalid)

Memory leak in django.utils.version.get_svn_revision

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

Description

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 15 years ago.

Download all attachments as: .zip

Change History (5)

by Ilya Semenov, 15 years ago

Attachment: 9107.patch added

comment:1 by Daniel Pope <dan@…>, 15 years ago

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()
3
>>> 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 by mrts, 15 years ago

Resolution: invalid
Status: closedreopened

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

Quote from http://jython.sourceforge.net/docs/differences.html:

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 by James Bennett, 15 years ago

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 by Ilya Semenov, 15 years ago

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