Posts tagged ‘Memory Management’

A handle leak in TWinControl?

For the TURBU engine, I’ve got a custom control that allows me to embed an OpenGL rendering context on a form.  I was working on some new features, and I downloaded gDEBugger, an OpenGL debugging tool, to help out.  One of the things it told me is that my rendering contexts were leaking. Continue reading ‘A handle leak in TWinControl?’ »

How default settings can slow down FastMM

One of the biggest challenges in working on the TURBU engine has been minimizing load times.  Some large projects have a whole lot of data to work with, which could take the better part of a minute to load if I tried to load it all up front.  No one wants to sit and wait for that, so I’ve pared down the loading so that only the stuff that’s needed right away gets loaded from the project database right at startup.

And yet, on one of my larger test projects, that wasn’t enough.  One of the things that has to be loaded upfront was map tile data, so that the maps can draw.  Unfortunately, this project has over 200 different tilesets, and it was taking quite a while to load that much data.  I’ve got a RTTI-based deserializer that can turn dataset records into objects, but it was taking a completely unreasonable 3.3 seconds to read the tile data.

Continue reading ‘How default settings can slow down FastMM’ »

Delphi memory management made simple

Most of my posts on here have been about technical subjects, geared towards moderate-to-advanced Delphi coders.  This one’s to help out the beginners who are still learning the ropes.  I’d like it to be something that people can send new users to from StackOverflow or other sites if they’re having trouble figuring out how to clean up their memory properly.

I’ve never really understood why people find memory management difficult.  Maybe I just “get it” for some reason, but it’s never seemed all that arcane or complex to me.  In all my time working with Delphi, I’ve only run into one truly difficult memory management scenario, and it’s something that most people won’t ever have to deal with: sharing global interface references across package boundaries.  If you do that wrong, you’re likely to run into some very strange errors at program shutdown that are hard to debug.

But people keep asking questions about the basics of what to free and how to free it on StackOverflow, and from answering them and analyzing the questions and the answers, it seems to me that the entirety of memory management can be boiled down to one single principle.

Continue reading ‘Delphi memory management made simple’ »