Retaining an object vs. Re-initializing it
<p>Well I guess this is not a normal how-to-do-this-or-that stackoverflow question, but perhaps someone could enlighten me of a better approach for this question.</p>

<p>I've created an interface that could inherit different "engines" depending on a value and return the same object for all engines.
This is a short time flat rentals application that has some integration with other applications in other states, obviously each one has a API, so I have to know how to send and receive each one differently and inside my application to be able to have the same object for all APIs.
What I do exactly is I initialize something like this.</p>

<p><code>$flat = new API(array('engine' =&gt; 'some_api')); // the array has some more information inside but it is unimportant for the question</code> </p>

<p>Now I have a list of IDs that each of them is for a different API.
Something like</p>

<p><code>$list = array(1 =&gt; 'api_1', 2 =&gt; 'api_2'); // and more ...</code></p>

<p><strong>Now for the question!</strong></p>

<p>When iterating over the <code>$list</code> what would <em>you</em> think is better,
Retaining all the possible engines inside the API object and for each ID I already have the "engine" initialized inside the API object (probably better speed/performance as everything is already allocated) <strong>or</strong> should foreach ID create a new API object with only the right "engine" initialized. (Lesser speed/performance but should be better on the memory management).</p>

<p>The API object has no meaning outside of the scope of the iteration so there is no need to retain it further down the line, but perhaps there would be less garbage collection overhead all in all if I just initiate one object instead of say 2 or 4 for the amount of IDs I have.</p>

<p>Any thoughts?</p>
