How to free up memory used by widgets?

148 views
Skip to first unread message

tarik setia

unread,
Jan 29, 2021, 1:54:48 PM1/29/21
to Kivy users support
I am building a kivy app.
One of the screen (Screen1) uses a lot of memory. So, when transitioning to another screen, I tend to delete the children for screen1. But even that is not freeing up the memory.


Link to app code(minimal version):

Steps:
pip install -r requirements.txt
python app.py

the code for screen1 is in screes/alert_Detail_screen.py

Any Help is much appreciated.
Thanks in advance
Tarik

Elliot Garbus

unread,
Jan 29, 2021, 2:59:14 PM1/29/21
to kivy-...@googlegroups.com

I imaging you would need to force the Python garbage collector to free the memory.  Unless there is a specific reason to free memory I would be inclined to just let the GC handle it.

 

https://docs.python.org/3/library/gc.html

see gc.collect

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/97ebb191-9e12-49c9-b200-ea1121327077n%40googlegroups.com.

 

tarik setia

unread,
Jan 29, 2021, 5:31:16 PM1/29/21
to Kivy users support
Memory is needs to be freed up instantly, Drawing polygon mapview causes the spike in memory, User may revisit alert details for a different alert and  each time, a new polygon will be drawn.
This causes memory usage to reach Gbs instantly.

I tried calling gc.collect() when on_leave() is triggered. But no success.

If and when your time allow, could you please take a look at the code and see if I am doing something wrong?

-Tarik

Elliot Garbus

unread,
Jan 29, 2021, 6:47:21 PM1/29/21
to kivy-...@googlegroups.com

Taking a look at your code:

  1. You are creating a new MapView object everytime you enter the AlertDetailScreen.  I would recommend creating one MapView object in the screen in __init__(), and reusing it.

 

  1. At the bottom of the alert_details_screen.py you are creating another App instance.  There can only be one App instance in a kivy app.  If this is for testing, put it under a if __name__ ==  ‘__main__’:

 

  1. You are calling draw_polygons() everytime you enter the screen.  It would seen to me after you create a map, and draw on it. You would only need to redraw it if something has changed.  You are also creating a new GeoJsonMapLayer() each time.

 

If these actions don’t help. I’d also suggest looking for a python memory profiling tool so you know what is driving the memory consumption.

There is also a kivy Cache manager that keeps image data around.  You could also take a look there – but I would recommend starting by not creating new map objects every time you enter the screen.

Reply all
Reply to author
Forward
0 new messages