Drawing sine curve in Memory-Used view of Task Manager on Windows 10?
<p>I am trying to write a simple proof-of-concept script on Windows 10 that let's me draw the absolute of a sin curve in the task manager memory window.</p>

<p>My code is as follows:</p>

<pre><code>import time
import math
import gc
import sys

x = 1
string_drawer = []

while True:

    #Formula for the eqaution (sin curve)
    y = (abs(math.sin(math.radians(100*x))))*512000000
    print (y, type(y))

    #Making y type 'int' so that it can be used to append
    y = int(round(y))
    print (y, type(y))

    #Checking the size of string_drawer for debugging
    print(sys.getsizeof(string_drawer))

    #Loop used for appending
    if sys.getsizeof(string_drawer) &lt; y: #If y is bigger, find the difference and append
        y = y - sys.getsizeof(string_drawer)
        string_drawer.append(' ' *y)
    elif sys.getsizeof(string_drawer) &gt; y: #If y is smaller, delete the variable and make a new one
        string_drawer = [] *y
    else: #If y is the same size as string_drawer, do nothing
        string_drawer = string_drawer

    #Call the Python gerbage colector
    gc.collect()

    #Sleep to make sure Task Manager catches the change in RAM usage
    time.sleep(0.5)

    #Increment x
    x += 1
    print(x, type(x))
</code></pre>

<p>What I am getting is as follows:
<img src="http://i.stack.imgur.com/ahEsx.png" alt="Image"></p>

<p>What I want is this:
<img src="http://i.stack.imgur.com/UXPYc.png" alt="Image 2"></p>

<p>Do you have an idea of what I am doing wrong? My guess is that is is something within the if loop or something regarding the garbage collector.</p>

<p>Any help is appreciated. Thanks :)</p>

<pre><code>sys.getsizeof(string_drawer)
</code></pre>

<blockquote>
  <p>Return the size of an object in bytes. The object can be any type of
  object. All built-in objects will return correct results, but this
  does not have to hold true for third-party extensions as it is
  implementation specific.</p>
  
  <p><strong>Only the memory consumption directly attributed to the object is accounted for, not the memory consumption of objects it refers to.</strong></p>
</blockquote>

<p>And you are appending to a list of strings so the getsizeof will return the memory attributed to the list not the size of the strings of spaces it refers to.
Change the list for a string </p>

<pre><code>string_drawer = ''
string_drawer += ' ' * y
</code></pre>

<p>but then you can and should use <code>len</code> instead of <code>sys.getsizeof</code> because the later adds the size of the garbage collector (although if the string is large enough it is negligible), also if you want to do nothing then do nothing:</p>

<pre><code>else: #If y is the same size as string_drawer, do nothing
    pass
</code></pre>

<p>and to reset the string do <code>string_drawer = ''</code>, not as you do with the list <code>string_drawer = [] * y</code> </p>

python memory-management garbage-collection