PhpRiot
Follow phpriot on Twitter
Sponsored Link
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

Managing Memory Objects

This section describes creating and destroying objects in the managed memory, and settings to control memory manager behavior.

Creating Movable Objects

Create movable objects (objects, which may be swapped) using the Zend_Memory_Manager::create([$data]) method:

<?php
$memObject 
$memoryManager->create($data);

The $data argument is optional and used to initialize the object value. If the $data argument is omitted, the value is an empty string.

Creating Locked Objects

Create locked objects (objects, which are not swapped) using the Zend_Memory_Manager::createLocked([$data]) method:

<?php
$memObject 
$memoryManager->createLocked($data);

The $data argument is optional and used to initialize the object value. If the $data argument is omitted, the value is an empty string.

Destroying Objects

Memory objects are automatically destroyed and removed from memory when they go out of scope:

<?php
function foo()
{
    global 
$memoryManager$memList;

    ...

    
$memObject1 $memoryManager->create($data1);
    
$memObject2 $memoryManager->create($data2);
    
$memObject3 $memoryManager->create($data3);

    ...

    
$memList[] = $memObject3;

    ...

    unset(
$memObject2); // $memObject2 is destroyed here

    
...
    
// $memObject1 is destroyed here
    // but $memObject3 object is still referenced by $memList
    // and is not destroyed
}

This applies to both movable and locked objects.

Zend Framework