Free ram decrease in every cycle

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Bobricius
 
Posts: 14
Joined: Thu Jul 20, 2017 6:28 am

Free ram decrease in every cycle

Post by Bobricius »

Hi I have stupid beginner question, I try display free ram, but it quickly decrease in cycle to zero and then to max, is it normal????
https://youtu.be/OLCY_EU78bo

Code: Select all

while True:
	text =  "Free ram:"+str(gc.mem_free())
	text_area = label.Label(terminalio.FONT, text=text, scale=3)
	text_area.x = 10
	text_area.y = 10
	#time.sleep(1)
	display.show(text_area)

User avatar
dastels
 
Posts: 15674
Joined: Tue Oct 20, 2015 3:22 pm

Re: Free ram decrease in every cycle

Post by dastels »

In short, yes.

When you do things that allocate objects (like crating that Label) or otherwise consume memory it takes it from the free memory. The amount of free memory will decrease over time if you wantonly use memory (there are ways to minimize that). When it gets below a certain amount (or some other criteria... I'm not sure what exactly CircuitPython uses) the garbage collector executes and tidies up, reclaiming memory that isn't being used any more.

Dave

User avatar
adafruit2
 
Posts: 22149
Joined: Fri Mar 11, 2005 7:36 pm

Re: Free ram decrease in every cycle

Post by adafruit2 »

you probably want to create the label once, then change the text whenever the value to display changes

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”