コード例 #1
0
ファイル: GCHelper.cs プロジェクト: zwywilliam/USharp
 public static void CollectGarbage(bool managedOnly)
 {
     if (managedOnly)
     {
         Native_GCHelper.CollectGarbage();
     }
     else
     {
         UObject.CollectGarbage();
     }
 }
コード例 #2
0
ファイル: GCHelper.cs プロジェクト: zwywilliam/USharp
        internal static void OnNativeFunctionsRegistered()
        {
            onAdd    = new Native_GCHelper.Del_Add(OnAdd);
            onRemove = new Native_GCHelper.Del_Remove(OnRemove);

            Native_GCHelper.Set_OnAdd(onAdd);
            Native_GCHelper.Set_OnRemove(onRemove);

            objectInternalIndexOffset = Native_GCHelper.GetInternalIndexOffset();

            FCoreUObjectDelegates.PostGarbageCollect.Bind(OnPostGarbageCollect);
        }
コード例 #3
0
        internal static void OnNativeFunctionsRegistered()
        {
            onAdd         = new Native_GCHelper.Del_Add(OnAdd);
            onAddExisting = new Native_GCHelper.Del_AddExisting(OnAddExisting);
            onRemove      = new Native_GCHelper.Del_Remove(OnRemove);

            Native_GCHelper.Set_OnAdd(onAdd);
            Native_GCHelper.Set_OnAddExisting(onAddExisting);
            Native_GCHelper.Set_OnRemove(onRemove);

            FCoreUObjectDelegates.PostGarbageCollect.Bind(OnPostGarbageCollect);
        }
コード例 #4
0
ファイル: GCHelper.cs プロジェクト: zwywilliam/USharp
        internal static void OnUnload()
        {
            // Call unload on all managed objects until there are no objects left to process

            // Find which types implement OnAssemblyUnload or OnAssemblyReload
            Dictionary <Type, bool> typesRequiringUnloadOrReload = new Dictionary <Type, bool>();

            List <IntPtr> allUnloadOrReloadReferences = new List <IntPtr>();

#if ARRAY_GC
            Dictionary <IntPtr, UObjectRef> references = new Dictionary <IntPtr, UObjectRef>();
            foreach (UObjectRef objRef in References)
            {
                if (objRef != null)
                {
                    references.Add(objRef.Native, objRef);
                }
            }
#else
            Dictionary <IntPtr, UObjectRef> references = new Dictionary <IntPtr, UObjectRef>(References);
#endif
            Dictionary <IntPtr, UObjectRef> newReferences = new Dictionary <IntPtr, UObjectRef>(references);
            while (newReferences.Count > 0)
            {
                foreach (KeyValuePair <IntPtr, UObjectRef> reference in newReferences)
                {
                    UObject obj = reference.Value.Managed;
                    if (obj != null && !obj.IsDestroyed)
                    {
                        bool requiresUnloadOrReload;
                        Type type = obj.GetType();
                        if (!typesRequiringUnloadOrReload.TryGetValue(type, out requiresUnloadOrReload))
                        {
                            MethodInfo unloadMethod = type.GetMethod("OnAssemblyUnload");
                            if (unloadMethod.DeclaringType != typeof(UObject))
                            {
                                requiresUnloadOrReload = true;
                            }
                            else
                            {
                                MethodInfo reloadMethod = type.GetMethod("OnAssemblyReload");
                                if (reloadMethod.DeclaringType != typeof(UObject))
                                {
                                    requiresUnloadOrReload = true;
                                }
                            }
                            typesRequiringUnloadOrReload.Add(type, requiresUnloadOrReload);
                        }

                        if (requiresUnloadOrReload)
                        {
                            reference.Value.Managed.OnAssemblyUnload();
                            allUnloadOrReloadReferences.Add(reference.Key);
                        }
                    }
                }
                newReferences.Clear();
#if ARRAY_GC
                foreach (UObjectRef objRef in References)
                {
                    if (objRef != null && !references.ContainsKey(objRef.Native))
                    {
                        references.Add(objRef.Native, objRef);
                        newReferences.Add(objRef.Native, objRef);
                    }
                }
#else
                foreach (KeyValuePair <IntPtr, UObjectRef> reference in References)
                {
                    if (!references.ContainsKey(reference.Key))
                    {
                        references.Add(reference.Key, reference.Value);
                        newReferences.Add(reference.Key, reference.Value);
                    }
                }
#endif
            }

            // Save all of the objects which we called OnAssemblyUnload on so that we can call
            // OnAssemblyReload when hotreload reloads.
            GCHelperHotReloadData hotReloadData = HotReload.Data.Create <GCHelperHotReloadData>();
            foreach (IntPtr address in allUnloadOrReloadReferences)
            {
                hotReloadData.Objects.Add(new FWeakObjectPtr(address));
            }

            Native_GCHelper.Clear();
        }
コード例 #5
0
ファイル: GCHelper.cs プロジェクト: zwywilliam/USharp
 private static void OnPostGarbageCollect()
 {
     FMessage.Log("OnPostGarbageCollectBegin");
     Native_GCHelper.CollectGarbage();
     FMessage.Log("OnPostGarbageCollectEnd");
 }
コード例 #6
0
ファイル: GCHelper.cs プロジェクト: zwywilliam/USharp
 public static void Remove(IntPtr native)
 {
     Native_GCHelper.Remove(native);
 }
コード例 #7
0
ファイル: GCHelper.cs プロジェクト: zwywilliam/USharp
 private static IntPtr Add(IntPtr native)
 {
     return(Native_GCHelper.Add(native));
 }