mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
MemoryManager: Look inside Closure objects to resolve dependencies
the lack of closure analysis allowed several memory leaks to be unable to be debugged using memory dumps.
This commit is contained in:
parent
7b02cc3efd
commit
b8e1bdbed4
@ -399,13 +399,25 @@ class MemoryManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$objects[$hash] = true;
|
$objects[$hash] = true;
|
||||||
|
|
||||||
$reflection = new \ReflectionObject($object);
|
|
||||||
|
|
||||||
$info = [
|
$info = [
|
||||||
"information" => "$hash@$className",
|
"information" => "$hash@$className",
|
||||||
"properties" => []
|
|
||||||
];
|
];
|
||||||
|
if($object instanceof \Closure){
|
||||||
|
$info["definition"] = Utils::getNiceClosureName($object);
|
||||||
|
$info["referencedVars"] = [];
|
||||||
|
$reflect = new \ReflectionFunction($object);
|
||||||
|
if(($closureThis = $reflect->getClosureThis()) !== null){
|
||||||
|
$info["this"] = self::continueDump($closureThis, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: scan non-closures for statics as well
|
||||||
|
foreach($reflect->getStaticVariables() as $name => $variable){
|
||||||
|
$info["referencedVars"][$name] = self::continueDump($variable, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$reflection = new \ReflectionObject($object);
|
||||||
|
|
||||||
|
$info["properties"] = [];
|
||||||
|
|
||||||
foreach($reflection->getProperties() as $property){
|
foreach($reflection->getProperties() as $property){
|
||||||
if($property->isStatic()){
|
if($property->isStatic()){
|
||||||
@ -418,6 +430,7 @@ class MemoryManager{
|
|||||||
|
|
||||||
$info["properties"][$property->getName()] = self::continueDump($property->getValue($object), $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
$info["properties"][$property->getName()] = self::continueDump($property->getValue($object), $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fwrite($obData, json_encode($info, JSON_UNESCAPED_SLASHES) . "\n");
|
fwrite($obData, json_encode($info, JSON_UNESCAPED_SLASHES) . "\n");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user