public static string MemoryLeakReport(this LuaEnv env, Data data, int maxLevel = 10) { env.FullGc(); var relationshipInfo = getRelationship(env); StringBuilder sb = new StringBuilder(); sb.AppendLine("total memroy: " + data.Memroy); foreach (var kv in data.TableSizes) { List <RefInfo> infos; if (!relationshipInfo.TryGetValue(kv.Key, out infos)) { continue; } List <string> paths = new List <string>(); for (int i = 0; i < maxLevel; i++) { int pathCount = paths.Count; paths.AddRange(infos.Where(info => !info.HasNext).Select(info => info.Key)); if ((paths.Count - pathCount) != infos.Count) { infos = infos.Where(info => info.HasNext) .SelectMany((info) => { List <RefInfo> infosOfParent; if (!relationshipInfo.TryGetValue(info.Parent, out infosOfParent)) { return(new List <RefInfo>()); } return(infosOfParent.Select(pinfo => { var parentkey = pinfo.Key; return new RefInfo() { HasNext = pinfo.HasNext, Key = string.Format(info.IsNumberKey ? "{0}{1}" : "{0}.{1}", pinfo.Key, info.Key), Parent = pinfo.Parent, IsNumberKey = pinfo.IsNumberKey, }; })); }).ToList(); } else { break; } } infos = infos.Where(info => info.HasNext).ToList(); if (infos.Count != 0) { paths.AddRange(infos.Select(info => "..." + info.Key)); } sb.AppendLine(string.Format("potential leak({0}) in {{{1}}}", kv.Value, string.Join(",", paths.ToArray()))); } return(sb.ToString()); }
static int _m_FullGc(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLua.LuaEnv gen_to_be_invoked = (XLua.LuaEnv)translator.FastGetCSObj(L, 1); { gen_to_be_invoked.FullGc( ); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
void freeXLua() { luaEnv.FullGc(); luaEnv = null; Debug.Log("free XLua"); }
public static Data MemoryLeakCheck(this LuaEnv env, Data last) { env.FullGc(); return(findGrowing(last, getSizeReport(env))); }
public static Data StartMemoryLeakCheck(this LuaEnv env) { env.FullGc(); return(getSizeReport(env)); }