The memory_get_usage function can be used to track the memory usage. The ‘malloc’ function is not used for every block required, instead a big chunk of system memory is allocated and the environment variable is changed and managed internally.
The two different types of memory usages are −
The above mentioned memory usage can be tracked using memory_get_usage(). This function returns both real and actual memory used depending on our requirement.
For example: if we are looking at specific code snippets, internal memory might be relevant. On the other hand, if memory usage is being globally tracked, the real usage would be more relevant.