public virtual void Dispose()
        {
            ListPool <WeakReference> .Release(m_Owners);

            m_Owners = null;
            HashSetPool <string> .Release(m_Tags);
        }
Example #2
0
        public void UnloadUnusedBundles(string tag)
        {
            if (m_AssetBundles.Count == 0)
            {
                return;
            }

            AssetBundleReference abr = null;

            Stack <string> checkQueue = StackPool <string> .Get();

            HashSet <string> checkings = HashSetPool <string> .Get();


            Action <string> checkFun = (key) =>
            {
                abr = m_AssetBundles[key];
                checkings.Remove(key);

                if (abr.isUnused())
                {
                    //check dependencies
                    if (abr.dependencies != null && abr.dependencies.Count > 0)
                    {
                        foreach (AssetBundleReference sub in abr.dependencies)
                        {
                            //只有同样tag和空tag的ref才需要重新检查。
                            if (sub.inChain && (sub.tagCount == 0 || sub.HaveTag(tag)) && !checkings.Contains(sub.name))
                            {
                                checkQueue.Push(sub.name);
                            }
                        }
                    }

                    abr.Dispose();
                    m_AssetBundles.Remove(key);
                }
            };

            foreach (string key in m_AssetBundles.Keys)
            {
                abr = m_AssetBundles[key];
                if (abr.HaveTag(tag) && abr.inChain)
                {
                    checkQueue.Push(key);
                    checkings.Add(key);
                }
            }

            //recheck unused asset bundle
            while (checkQueue.Count > 0)
            {
                checkFun(checkQueue.Pop());
            }

            StackPool <string> .Release(checkQueue);

            HashSetPool <string> .Release(checkings);
        }
        protected override void Dispose(bool disposing)
        {
            Clean();
            if (m_Dependencies != null)
            {
                HashSetPool <AssetBundleReference> .Release(m_Dependencies);

                m_Dependencies = null;
            }
            base.Dispose(disposing);
        }
        void ReleaseDependencies()
        {
            var iter = m_Dependencies.GetEnumerator();

            while (iter.MoveNext())
            {
                iter.Current.Release();
            }
            HashSetPool <AssetBundleReference> .Release(m_Dependencies);

            m_Dependencies = null;
        }