What method or tool can be used to check out the memory occupied by all PHP variables or objects?

in fact, my problem comes from here:

Allowed memory size of 536870912 bytes exhausted (tried to allocate 12288 bytes) 

I think 512m is already very large. If it exceeds this size, there must be something wrong with the program, but the first thought of using breakpoint printing and debugging from top to bottom is too slow to locate which variable or object takes up too much memory at once. Can the request XDEBUG be realized?
or is there any other way to be faster?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e855c5-457d4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e855c5-457d4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?