I have an Flask application that used SQLAlchemy with MySQL as the database. I have a function defined like so:
def count_items():
total = 0
items = db.session.query(models.Item).yield_per(100)
for item in items:
total += 1
return total
It works as expected but the memory usage of uWSGI goes up by 100 MB every time I call it (the function is an app route so nothing else is being called). This can be repeated until the machine runs out of memory so I don't think it's just an issue of SQLAlchemy caching objects. Am I missing something obvious here for clearing the memory? If not, then are there any tips on how to debug it? I don't have the slightest idea where to start, especially with uWSGI in the mix.