Why does simple HTTP request cause to increase so much memory consumption?

I am tired of solving the question “Out of memory”. Why when I am do HTTP requests every time the memory consumption increase so much?
I just made Telegram-bot and put my commands (text messages) in eval(), with the help of it I try to add something to Google Spreadsheets.
So after every request memory consumption is getting bigger and bigger, then finally raise “Out of memory” error. Can someone help me, please?
Python

sheets = googleapiclient.discovery.build('sheets', 'v4')
sheets.spreadsheets().values().batchUpdate(spreadsheetId='my_id', body={
                'valueInputOption': 'USER_ENTERED',
                'data': [{'range': 'A1', 'majorDimension': 'ROWS', 'values': [[1]]}]
            }).execute()

There is not enough information in your message for someone else to be able to tell what the exact problem is.

You clearly have a memory leak - most likely you have some data that is read on each request and not discarded after it.

I take it your bot has a main loop where it waits for a request, then performs an action, and then waits for another request.

You probably have an object always visible in that scope that has data added to it somehow.

2 Likes

Thanks. Seems, there is some problems with googleapiclient, because gspread works much better (and there is no even memory consumption).