Reassigning an array frees the memory used by it?

My class has a member variable array, items. Periodically I reassign the array to be the value of another, temporary array, like this:

$temp = array(); $temp[] = new Object(); $temp[] = new Object(); $temp[] = new Object(); ... etc. $this->items = $temp;

So, could I have a memory leak? By reassigning the value of $this->temp to a new value, $temp, would all the items (the items are objects) originally in $this->temp still linger around, or would they be freed?


This will not cause a memory leak. $temp and $this->items are just references to the same array. Since PHP is a garbage collected language, the array will be deleted (garbage collected) when there are no more references to the array.


They will linger around for a little while, but in PHP they will be freed eventually by the garbage collector.


  • How to find out if an Entity Framework object has changed?
  • jquery remove from droppable when dragged out
  • Inserting iterator range in std::vector
  • Send data from service to activity and screen rotation
  • Why does PostgresSQL reassign role command, change template database's owner
  • Best way to initialise / clear a string variable cocoa
  • Generate a business key
  • Can't find cygwin setup.exe file?
  • NSMutableArray Access Issue
  • C++ Pointer Arrays
  • Where these are stored?
  • NSIS decompiler
  • What does “t” refer to in this SQL?
  • How to 'create temp table as select' in Slick?
  • How load cv2.KeyPoint and Descriptors correctly on OpenCV 3 with Python 3?
  • SetWindowsHookEx does not react on media keys
  • Spark job failing in YARN mode
  • Paperclip, set path outside of rails root folder
  • Fetching methods from BroadcastReceiver to update UI
  • DotNetZip - Calculate final zip size before calling Save(stream)
  • output of program is not same as passed argument
  • htaccess rewriting URLs with multiple forward slashes
  • Weird JavaScript statement, what does it mean?
  • How do you troubleshoot character encoding problems?
  • AT Commands to Send SMS not working in Windows 8.1
  • How to format a variable of double type
  • Cannot Parse HTML Data Using Android / JSOUP
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Benchmarking RAM performance - UWP and C#
  • Trying to get generic when generic is not available
  • How do I configure my settings file to work with unit tests?
  • Java static initializers and reflection
  • Is it possible to post an object from jquery to bottle.py?
  • unknown Exception android
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?