Why does GraphicRaycaster still refer BackGround Texture when UI is destroyed ?

My Game has a SelectHeroUI in the beginning. It’s a child of a gameObject called SelectLayer which 's attached with a GraphicRaycaster and a Canvas. The SelectHeroUI’s background Texture takes up a large memory,so I want to release it after the Player selects a hero and gets ready.The code is just like this below.

 DestroySelectHeroUI(); // I used GameObject.DestroyImmediate
 Resources.UnloadUnusedAssets();

But After I destroyed this UI,I Checked the profiler and found the background texture was still in the memory and was refered by the SelectLayer.


Is there anything I got wrong?

Well, I solved the problem by myself.
The GraphicRaycaster has a list of RaycastResults 136555-kp7cxhvyl5d-j.png

After i destroyed the UI Panel,The list didn’t clear itself and still refered all graphics,so the bg’s graphic was refered and cannot be gc ,which makes the texture cannot be unloaded,either.

If i clear the Results list and call UnloadUnusedAssets again, the texture will be released.

But unfortunately the list is private and GraphicRaycaster has no interface to clear it. I try to destory the current graphicRayCaster and add a new one, but I cannot change the new GraphicRayCaster’s BlockingMask(protected) in my code.

By now I have to add a function into the class GraphicRaycaster for clearing.

        public void ClearRaycastResults()
        {
            if(m_RaycastResults != null)
            {
                m_RaycastResults.Clear();
            }
        }

at least this works fine : )

EDIT:It seems that I can use Reflection to clear the results,too.

public static void ClearRaycastResults(GraphicRaycaster gRaycaster)
        {
            if(gRaycaster != null)
            {
                var fieldInfo = gRaycaster.GetType().GetField("m_RaycastResults", BindingFlags.NonPublic | BindingFlags.IgnoreCase | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    List<Graphic> list = fieldInfo.GetValue(gRaycaster) as List<Graphic>;
                    if(list != null)
                    {
                        list.Clear();
                    }
                }
            }
        }