The first mistake we’ll talk about is not necessarily exclusive to WebApp development, but something we often see . It’s not cleaning up objects that you created within functions. The reason we’re highlighting it here is that we often see this happen when working with the JSON parser within a Web Application. Take the following code for example.
In this code we can see that we are creating a cJsonObject to hold the data that we got from an external service. The data in the JsonObject is then processed in our application, and the routine ends. While this works, the problem here is that we dynamically created a JsonObject. This object is not handled by the garbage collection, so if we don’t clean it up ourselves it will linger in our memory forever until the application is terminated. This can eventually cause the memory to be full, causing the application to crash.
The way to correct this is by simply cleaning up the object when we’re done with it by calling on Send Destroy of oJsonObject. This cleans up the object and frees up the memory that was allocated to it.
In short: Make sure you always clean up any objects that were manually created inside a function.