title: Using Stack Allocation instead of Heap allocation for factory methods
body: <p>I am trying to refactor some code. Currently that code follows pattern like :</p>
  
  <pre><code>function f() {
  Transaction trans;
  // Do Operation
  trans.commit();
  }
  </code></pre>
  
  <p>Here transaction is concrete class. I want to move it to Interface and make this code look like as:</p>
  
  <pre><code>function f() {
  ITransaction* trans = GetTransaction();
  // Do Operation
  trans-&gt;commit();
  }
  
  // Factory 
  ITransaction* GetTransaction()
  {
  return new Transaction();
  }
  </code></pre>
  
  <p>PROBLEM: we started using new here in factory method, which make heap allocation now. I want to avoid such heap allocation and still manage to use Interface. 
  Is there any way to achieve this?</p>
  
  <p>Thanks,
  Kailas</p>