User avatar
ttermeer-reboundcg
Topic Author
Posts: 17
Joined: 13 Sep 2019, 11:10
Contact:

Texture Memory Leak with Converter

10 Jun 2022, 15:40

So we have converter that transforms bindings into an image using Texture2D and TextureSource from Noesis. This works well to display the image but it comes with a big issue, the unity texture is never freed and can quickly ramp up if we start to display a lot of images. Since those are created with the converter, I do not see an any way to track which is still in use.

Any idea on how to solve this ?
 
Faerdan
Posts: 73
Joined: 02 Oct 2015, 09:11
Location: Galway, Ireland
Contact:

Re: Texture Memory Leak with Converter

10 Jun 2022, 16:41

Hi ttermeer-reboundcg,

Our solution to this was to use Unity Addressables (https://docs.unity3d.com/Packages/com.u ... index.html), and integrate that with Noesis using an AddressableImage control.

In case you don't know, Addressables is a system for building and loading Unity AssetBundles, using the asset GUID or a custom key.

Our AddressableImage control internally uses the Addressables API to load the texture using the Source as an Addressable asset key. It then releases/unloads the texture when the Source binding changes or the control is disposed.

Another benefit is that in Blend/WPF AddressableImage works as a regular Image, using the Source as an image file path instead of as an Addressable asset key.

Our AddressableImage control is heavily integrated with our code base, but if this is of interest to you I'll write a new AddressableImage class which can be used in any project.
 
Faerdan
Posts: 73
Joined: 02 Oct 2015, 09:11
Location: Galway, Ireland
Contact:

Re: Texture Memory Leak with Converter

12 Jun 2022, 21:32

I've created the AddressableImage control, along with an example project showing it in use: viewtopic.php?t=2629
 
User avatar
ttermeer-reboundcg
Topic Author
Posts: 17
Joined: 13 Sep 2019, 11:10
Contact:

Re: Texture Memory Leak with Converter

13 Jun 2022, 11:46

We cannot use addressables as we requires to be loaded on the fly for modding.

Either way I think the issue is from within Noesis. It seems the UnregisterTextureCallback is not called when the binding changes.
 
Faerdan
Posts: 73
Joined: 02 Oct 2015, 09:11
Location: Galway, Ireland
Contact:

Re: Texture Memory Leak with Converter

13 Jun 2022, 12:04

I don't know what/where the UnregisterTextureCallback is, so I may be missing something here.

Noesis does not manage the lifecycle of textures that are passed to it via a TextureSource, it only does this for the textures it loads internally. Noesis can't know whether the texture is being used in other places, or should remain in memory for caching purposes.

You can't use a converter to manage the lifecycle of a resource. You could use a technique similar to my AddressableImage, using a custom control to load and dispose of the texture. You don't need to inherit from the Image class, I did that for convenience, instead you could create a custom control which has the input dependency property (whatever input you were using for the converter) and a readonly ImageSource Source dependency property. In this custom control's ControlTemplate you would have an Image and use a template binding to bind that Image.Source to your custom control's readonly Source property. I'm busy this morning and can't go into detail, but if you're interested I can expand on this later.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Texture Memory Leak with Converter

15 Jun 2022, 11:01

Hi ttermeer, could you please share the code of the converter and the related xaml to understand what path are you following so we can do some tests on our side?
 
User avatar
ttermeer-reboundcg
Topic Author
Posts: 17
Joined: 13 Sep 2019, 11:10
Contact:

Re: Texture Memory Leak with Converter

15 Jun 2022, 11:07

I created a ticket with all infos : https://www.noesisengine.com/bugs/view.php?id=2360
So far I have only been able to reduce the issue by creating a texture cache system using WeakReference
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Texture Memory Leak with Converter

15 Jun 2022, 11:12

Thanks for the detailed report.

Who is online

Users browsing this forum: No registered users and 89 guests