Terminate the app

When the user closes the Falling Blocks app, glview_loop() invokes the finalize() callback. We need to do some clean-up to free up resources before the app closes.

static void finalize(void *data) {
    app_t *app = (app_t*)data;
    free(app->boxes);
    free(app);
}

We need to free the memory that was allocated for the blocks. Because we used calloc() to allocate the memory, we should free it manually to make sure that we don't create a memory leak. The system should deallocate this memory anyways, but it's a good practice to do it explicitly when we're done using it.

free(app->boxes);

That's it! Let the blocks fall where they may! You can try altering the app to use the z-axis and give the falling blocks a 3-D effect or change the color and size of the blocks.

Last modified: 2015-03-31



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus