Fix resource leak in hdSt
Description of Change(s)
Garbage collect the texture handle registry and resource registry to prevent memory leaks.
Submitting on behalf of Maddy Adams
- [X] I have verified that all unit tests pass with the proposed changes
- [X] I have submitted a signed Contributor License Agreement
Filed as internal issue #USD-9643
/AzurePipelines run
Azure Pipelines successfully started running 1 pipeline(s).
I am missing some context about how this memory leak came about and what the repro steps are.
Looking at this again, I noticed that HdStResourceRegistry::GarbageCollect doesn't call GarbageCollect on the HdSt_TextureHandleRegistry. That seems a problem.
My suggested fix is this: Rename HdSt_TextureHandleRegistry::_GarbageCollectAndComputeTargetMemory to GarbageCollect and make it public. Call it from HdStResourceRegistry::GarbageCollect. HdStResourceRegistry::~HdStResourceRegistry calls GarbageCollect already which should be called from HdStRenderDelegate::~HdStRenderDelegate when dropping the shared_ptr to the resource registry.
That should fix the memory leak under the following assumptions:
- We fully depopulate the render delegate so that no materials or render buffers are holding on to the textures.
- No one but the render delegate is holding on to a shared ptr to the resource registry. HdStRenderDelegate::GetResourceRegistry should arguably return a raw pointer.
- The Hgi instance is alive when we destruct the HdStRenderDelegate.
In a couple of days, the change I described above and checked in should appear here. Can you confirm it fixes the leak?
I’ll be out for a couple weeks but I’ll confirm when I’m back.
On Wed, Jul 17, 2024 at 11:39 AM Matthias Goerner @.***> wrote:
In a couple of days, the change I described above and checked in should appear here. Can you confirm it fixes the leak?
— Reply to this email directly, view it on GitHub https://github.com/PixarAnimationStudios/OpenUSD/pull/3070#issuecomment-2234002308, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABB4XUXORTB7VGDVPF37JFTZM227XAVCNFSM6AAAAABHJPGCUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZUGAYDEMZQHA . You are receiving this because you authored the thread.Message ID: @.***>
@dgovil the commit Matthias is referring to is here: https://github.com/PixarAnimationStudios/OpenUSD/commit/470623ac6484175f79cbc315c44d7568e9d7a6fa ... Let us know if this fixes the leak! If so I think we can close the PR out; otherwise we can iterate.
Thanks for finding this!
In my testing the latest patches seemed to have resolved this. I'll reopen if we encounter it again.
Thank you!