Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#9262 closed (invalid)

Memory leak in django.utils.version.get_svn_revision

Reported by: 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 semenov 8 years ago.

Download all attachments as: .zip

Change History (5)

Changed 8 years ago by semenov

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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 8 years ago by mrts

  • Resolution invalid deleted
  • Status changed from closed to reopened

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 8 years ago by ubernostrum

  • Resolution set to invalid
  • Status changed from reopened to closed

"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 8 years ago by 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