Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Does the above even make sense, or do I have to look for the problem elsewhere? Is it just an unfortunate accident that significant data is kept around for so long in this particular use case?</p> </blockquote> <p>Yes, it does make sense. And yes, there are other issues worth to consider. Django uses <code>threading.local</code> as base for <code>DatabaseWrapper</code> (and some contribs use it to make request object accessible from places where it's not passed explicitly). These global objects survive requests and can keep references to objects till some other view is handled in the thread.</p> <blockquote> <p>Is there anything I can do to avoid the issue. I already see some potential to optimize the view, but that appears to be a solution with limited scope - although I am not sure what I generic one would be, either; how advisable is it for example to call gc.collect() or gc.set_threshold() manually?</p> </blockquote> <p>General advice (probably you know it, but anyway): avoid circular references and globals (including <code>threading.local</code>). Try to break cycles and clear globals when django design makes hard to avoid them. <code>gc.get_referrers(obj)</code> might help you to find places requiring attention. Another way it to disable garbage collector and call it manually after each request, when it's the best place to do (this will prevent objects from moving to the next generation).</p> <blockquote> <p>I don't suppose there is a way to do a gc.get_objects() by generation, i.e. only retrieve the objects from generation 2, for example?</p> </blockquote> <p>Unfortunately this is not possible with <code>gc</code> interface. But there are several ways to go. You can consider the end of list returned by <code>gc.get_objects()</code> only, since objects in this list are sorted by generation. You can compare the list with one returned from previous call by storing weak references to them (e.g. in <code>WeakKeyDictionary</code>) between calls. You can rewrite <code>gc.get_objects()</code> in your own C module (it's easy, mostly copy-paste programming!) since they are stored by generation internally, or even access internal structures with <code>ctypes</code> (requires quite deep <code>ctypes</code> understanding).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload