Resource Dictionary memory leak
Posted: 06 Mar 2022, 15:16
Hello, I've been investigating memory leaks because every time we closed the editor we got an ensure in Noesis::Shutdown method. The size of the memory leak was 32 bytes.
So what I did was that I deleted all the user controls, custom controls, custom converters etc. to just have a basic noesis plugin without any UI and start investigation from there. Yet, I was still getting the same memory leak. So I dug a bit deeper and found that in NoesisSettings.cpp there is a ResourceDictionary initialization in SetApplicationResources() method. I commented out the Resource dictionary initialization like this:
And I was no longer getting the memory leak. That's how I got to think that the issue is with the ApplicationResourcesRef static raw pointer. I tried to find where is that pointer getting deallocated but to no avail, so what I did was I created a destructor for NoesisSettings class and put this in it:
To my understanding, when SetApplicationResources gets a nullptr as a parameter, it calls Release() on the ResourceDictionary (as per the code). The memory leak hasn't appeared since so I guess that solved it.
So I wanted to ask what do you think of this solution? Do you think the problem is somewhere else but this deallocation just successfully hides it? If so, where do you think the issue could be?
Or do you think that this is a solution that will not potentially break anything in game and that you will include this fix in the later versions of Noesis?
I am asking because this is a change that is "deeper" in Noesis and I don't just want to change things in there in order to bandaid something else.
Thank you very much for your work and I'm looking forward to seeing your response.
Have a nice day
// EDIT:
We consulted within the team and since we have heavily modified unreal engine it may have got broken along the way somewhere else.
From my investigation, the Shutdown method in UI.cpp gets correctly called after closing down the editor. It does release the gApplicationResources as well but for some reason it either gets reallocated or the issue is somewhere else, the ensure still shows 32 bytes allocated. Tried putting a break point into SetApplicationResources to check if it gets called twice but it does not. My investigation came to an end. I will probably leave the destructor there as I don't think it's gonna break anything. If you guys have any idea where that issue could be, please give me a hint.
So what I did was that I deleted all the user controls, custom controls, custom converters etc. to just have a basic noesis plugin without any UI and start investigation from there. Yet, I was still getting the same memory leak. So I dug a bit deeper and found that in NoesisSettings.cpp there is a ResourceDictionary initialization in SetApplicationResources() method. I commented out the Resource dictionary initialization like this:
Code: Select all
// ApplicationResourcesRef = LoadObject<UNoesisXaml>(nullptr, *ApplicationResources.GetAssetPathString(), nullptr, LOAD_NoWarn);
if (ApplicationResourcesRef)
{
ApplicationResourcesRef->AddToRoot();
uint32 Hash = ApplicationResourcesRef->GetContentHash();
if (ApplicationResourcesHash != Hash)
{
// ApplicationResourcesHash = Hash;
// Noesis::Ptr<Noesis::ResourceDictionary> Dictionary = Noesis::MakePtr<Noesis::ResourceDictionary>();
// Noesis::GUI::SetApplicationResources(Dictionary);
// ApplicationResourcesRef->LoadComponent(Dictionary);
}
}
Code: Select all
UNoesisSettings::~UNoesisSettings()
{
Noesis::GUI::SetApplicationResources(nullptr);
}
So I wanted to ask what do you think of this solution? Do you think the problem is somewhere else but this deallocation just successfully hides it? If so, where do you think the issue could be?
Or do you think that this is a solution that will not potentially break anything in game and that you will include this fix in the later versions of Noesis?
I am asking because this is a change that is "deeper" in Noesis and I don't just want to change things in there in order to bandaid something else.
Thank you very much for your work and I'm looking forward to seeing your response.
Have a nice day
// EDIT:
We consulted within the team and since we have heavily modified unreal engine it may have got broken along the way somewhere else.
From my investigation, the Shutdown method in UI.cpp gets correctly called after closing down the editor. It does release the gApplicationResources as well but for some reason it either gets reallocated or the issue is somewhere else, the ensure still shows 32 bytes allocated. Tried putting a break point into SetApplicationResources to check if it gets called twice but it does not. My investigation came to an end. I will probably leave the destructor there as I don't think it's gonna break anything. If you guys have any idea where that issue could be, please give me a hint.