Archive for the ‘reference’ Category.
June 22, 2010, 3:52 pm
Since some version of this question keeps showing up on StackOverflow, and the answer’s always basically the same, I figured I may as well write up a post on here that people can link to. Here’s the question, in simplified form:
“Why can’t I pass a TList<TMyDerivedObject> to a function that’s expecting a TList<TMyBaseObject>? You can pass a TMyDerivedObject to a parameter expecting TMyBaseObject, so why doesn’t it work for lists?”
Continue reading ‘Generics and the Covariance Problem’ »
March 25, 2010, 8:35 pm
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’ »