Python: Which will take less memory and execution is fast?
<p>I have a ResponseMessageService() class, Which have several methods.
I need only one method.</p>

<p>Then Which is better?</p>

<p>call that method directly? by</p>

<pre><code>    ResponseMessageService().WrongRegMsg(data="Your Reg ID is wrong!")
</code></pre>

<p>or take a object </p>

<pre><code>    response_message_service = ResponseMessageService()
</code></pre>

<p>Then call </p>

<pre><code>    response_message_service.WrongRegMsg(data="Your Reg ID is wrong!")
</code></pre>

<p>Which will took less memory and execution is first?</p>

<p>Regarding your question, </p>

<pre><code>ResponseMessageService().WrongRegMsg(data="Your Reg ID is wrong!")
</code></pre>

<p>would likely to take less memory.</p>

<p>Assigning the instance to a variable makes it retained in the memory, at least until the variable's name is unbound, for example, by using <code>del response_message_service</code></p>

python