There is a way to get the total memory PHP is using (memory_get_usage()) but how does one get the size in memory of an individual object?
I\'m obviously
Since clone (from Prof83's answer) didn't work for me, I tried to serialize and unserialize the variable whose size I want to measure:
function getMemoryUsage($var) {
$mem = memory_get_usage();
$tmp = unserialize(serialize($var));
// Return the unserialized memory usage
return memory_get_usage() - $mem;
}
I think it reports better results, at least for me.