I was successful in connecting the Raspberry Pi to the Cloud IoT and was able to toggle the device easily. But after a while, the device, according to me, times out of the connection, and shows "('on_disconnect', '1: Out of memory.')" and the connect status is set to False. So I reinstalled the git packages(the community folder) and repeated the same steps and I was successful again. But, obviously, the same error raised after a while. I can't seem to narrow it down to what is causing the issue. I am new here, so let me know if I should add anymore information.
EDIT: Since I was trying to narrow it down, I found out that re-running the "export GOOGLE_CLOUD_PROJECT=your-project-id-123" command when the above problem occurs, help me to establish connection properly(without changing anything). Although this doesn't stop the "Out of memory" issue, it's something to work with for now.
EDIT: https://github.com/GoogleCloudPlatform/community/tree/master/tutorials/cloud-iot-gateways-rpi Link to the folder