Opened 2 days ago

Last modified 2 days ago

#36662 new Cleanup/optimization

django.contrib.messages Storage creates circular references with Request objects — at Initial Version

Reported by: Raphael Gaschignard Owned by:
Component: contrib.messages Version: dev
Severity: Normal Keywords:
Cc: Raphael Gaschignard Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

To be honest I don't know how much people care about this kind of issue, but I am having some (very silly) operational issues downstream of Requests getting garbage collected at awkward times.

Request objects hold onto message storages via Request._messages. The storage classes hold references back to Request. This creates a reference cycle preventing Requests from being collected as fast as they could be (and can create some awkwardness in CPython, with del calls happening on associated objects in seemingly unrelated spots)

The "simple" fix here would be to hold onto request in the storage through a weakref, and add a property to get the request object on the storage class.

Change History (1)

by Raphael Gaschignard, 2 days ago

Attachment: cycle.2.png added

An example of the sort of cycle that appears (objgraph output)

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