pyblish / pyblish-base

Pyblish base library - see https://github.com/pyblish/pyblish for details.
Other
127 stars 59 forks source link

Cyclic dependency between Context and Instance #285

Open mottosso opened 8 years ago

mottosso commented 8 years ago
from pyblish.api
context = pyblish.api.Context()
instance = context.create_instance("MyInstance")

At this point, the Context holds a reference to MyInstance as a child of itself, and MyInstance holds a reference to Context through instance.parent and instance.context.

This means that neither can ever be freed from memory, causing a linear increase in memory use per added instance.

mottosso commented 8 years ago

This can be solved by storing a weak reference to the Context in each instance.

mottosso commented 8 years ago

I think another consequence of this is that the result dictionaries stored within the context during and after publishing would also never get garbage collected, resulting in ever-increasing memory use per reset and publish. Take a moment to think about how much data that can actually, every plug-in and log message is included there. Kilobytes per result, at least, multiplied by tens if not hundreds of results per publish.

tokejepsen commented 8 years ago

Guessing this is the source of the constant memory increase we have been reporting?

mottosso commented 8 years ago

Possibly. I've managed to plug this particular hole for now so it's likely we'll experience whether or not that's what it was. I'll be doing some proper memory hunting next.