Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda PHP Memory Model Overview | PHP Memory Model and Zend Engine
PHP Memory Management

bookPHP Memory Model Overview

Prerequisites
Pré-requisitos
Note
Definition

PHP uses automatic memory management, meaning the engine allocates and frees memory for variables without requiring manual control from the developer.

PHP's memory model is designed to simplify development while remaining efficient internally. Every time you assign a value to a variable, PHP automatically allocates memory. When the variable is no longer needed, that memory is released and reused. This approach reduces the risk of memory leaks. Understanding how PHP manages memory is important for large or long-running applications where performance and resource usage matter.

memory_usage.php

memory_usage.php

copy
1234567891011121314151617181920
<?php // Assign a string to a variable $name = "Alice"; // PHP allocates memory to store the string "Alice" // You can check current memory usage: echo "Memory usage after variable assignment: " . memory_get_usage() . " bytes\n"; // Assign an array to another variable $numbers = range(1, 1000); // PHP allocates more memory for the array echo "Memory usage after array assignment: " . memory_get_usage() . " bytes\n"; // Unset the array to free its memory unset($numbers); // PHP releases the memory used by $numbers echo "Memory usage after unsetting array: " . memory_get_usage() . " bytes\n"; ?>
question mark

Which statement best describes how PHP manages memory for variables?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 1

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

bookPHP Memory Model Overview

Deslize para mostrar o menu

Prerequisites
Pré-requisitos
Note
Definition

PHP uses automatic memory management, meaning the engine allocates and frees memory for variables without requiring manual control from the developer.

PHP's memory model is designed to simplify development while remaining efficient internally. Every time you assign a value to a variable, PHP automatically allocates memory. When the variable is no longer needed, that memory is released and reused. This approach reduces the risk of memory leaks. Understanding how PHP manages memory is important for large or long-running applications where performance and resource usage matter.

memory_usage.php

memory_usage.php

copy
1234567891011121314151617181920
<?php // Assign a string to a variable $name = "Alice"; // PHP allocates memory to store the string "Alice" // You can check current memory usage: echo "Memory usage after variable assignment: " . memory_get_usage() . " bytes\n"; // Assign an array to another variable $numbers = range(1, 1000); // PHP allocates more memory for the array echo "Memory usage after array assignment: " . memory_get_usage() . " bytes\n"; // Unset the array to free its memory unset($numbers); // PHP releases the memory used by $numbers echo "Memory usage after unsetting array: " . memory_get_usage() . " bytes\n"; ?>
question mark

Which statement best describes how PHP manages memory for variables?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 1
some-alt