To continue with this content, please log in with your Data Access ID or create a new account.
Cancel Data Access ID
You may not be authorized to see this content. Please contact Data Access Europe for more information.
Cancel Data Access Europe

DataFlex Courses

Information

Next lesson:
Not testing outside the debugger
Cancel

5 Common WebApp Mistakes

Lesson 1: Not cleaning up objects created in functions

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.