title: Python - increased memory usage when using a wrapper function?
body: <p>I wrote a test for a program and checked the memory usage. For some reason, wrapping the same operation in a function results in a polynomial (or maybe exponential) increase in memory usage. I am using <a href="https://pypi.python.org/pypi/memory_profiler" rel="nofollow">memory_profiler</a> to track memory usage, Python 2.7.1.</p>
  
  <p>Code:</p>
  
  <pre><code>def convertIntToBitint(number): return (pow(2, number - 1))
  </code></pre>
  
  <p>Test code and results (cleaned up a bit):</p>
  
  <pre><code>Line #    Mem usage    Increment   Line Contents
  23     9.070 MB     0.000 MB    def test_convertBigIntToBitint(self):
  24     9.070 MB     0.000 MB        result1 = convertIntToBitint(21000)
  25     9.070 MB     0.000 MB        answer1 = pow(2, 20999)
  27    10.496 MB     1.426 MB        result2 = convertIntToBitint(5015280)
  28    11.785 MB     1.289 MB        answer2 = pow(2, 5015279)
  30    70.621 MB    58.836 MB        result3 = convertIntToBitint(121000000)
  31    85.367 MB    14.746 MB        answer3 = pow(2, 120999999)
  </code></pre>
  
  <p>Why does <code>convertIntToBitint</code> take up more memory? And why doesn't the memory usage grow linearly?</p>
  
  <h2>EDIT for 2rs2ts</h2>
  
  <p>Interesting. Not sure if this is what you meant. </p>
  
  <pre><code>Line #    Mem usage    Increment   Line Contents
  23     9.074 MB     0.000 MB    def test_convertBigIntToBitint(self):
  24    56.691 MB    47.617 MB        result3 = convertIntToBitint(121000000)
  25    85.539 MB    28.848 MB        answer3 = pow(2, 120999999)
  26    85.539 MB     0.000 MB        result2 = convertIntToBitint(5015280)
  27    84.258 MB    -1.281 MB        answer2 = pow(2, 5015279)
  28    83.773 MB    -0.484 MB        result1 = convertIntToBitint(21000)
  29    81.211 MB    -2.562 MB        answer1 = pow(2, 20999)
  </code></pre>