Anyone know where I can find info on class constructors/destructors. It seems that class destructors never run when used in runtime packages, at least that's what I'm seeing. Wondering if that's as designed, or a known issue? Any references? The help wiki doesn't say much - http://docwiki.embarcadero.com/RADStudio/Seattle/en/Methods
Anyone know where I can find info on class constructors/destructors. It seems that class destructors never run when used in runtime packages, at least that's what I'm seeing. Wondering if that's as designed, or a known issue? Any references? The help wiki doesn't say much - http://docwiki.embarcadero.com/RADStudio/Seattle/en/Methods
I'm trying to clean up my shutdown code so I can see the wood for the trees in the fastmm leak reports.
I'm trying to clean up my shutdown code so I can see the wood for the trees in the fastmm leak reports.
out of curiosity, do the class constructors get called?
ReplyDeleteYes they do.
ReplyDelete/sub
ReplyDeleteThat's interesting. I don't use runtime packages, so I don't have any experience with it - but - at what point would you expect the cleanup to be done? Is there an explicit point of unloading a package?
ReplyDeleteAccording to the doco, class destructors are called when unit finalization is done.. but I've also now discovered that the finalization sections never get executed in my package! I have had to resort to creating a cleanup method that I call during shutdown, messy but needed.
ReplyDeleteMaybe of interrest:
ReplyDeletehttp://stackoverflow.com/questions/7566954/why-code-in-any-unit-finalization-section-of-a-package-is-not-executed-at-start
Class constructors are called from the initialization section. Class destructors are called from the finalization section. That's independent of the type of module. So, if you are not finalizing your units, why not? That's the real question.
ReplyDeleteDavid Heffernan , and if you declare a generic class constructor in the .dpr file, they will not run. Bug http://qc.embarcadero.com/wc/qcmain.aspx?d=103798 "Class constructors for generic classes do not run if all code is in a .dpr file"
ReplyDeleteStill not fixed in #10Seattle
Leif Uneus Hmm, that sounds familiar ....
ReplyDeleteDavid Heffernan Indeed, since you reported the issue :-)
ReplyDeleteIs this a general condition or only true for Designtime Packages and Experts loaded into Delphi IDE bds.exe? Do you have Andreas Hausladen's IDE Fix pack?
ReplyDeleteWarren Postma It's well known that properly unloaded packages finalize their units. No need for any fix packs. Clearly Vincent is not unloading properly.
ReplyDeleteDoesn't Andreas have a mode in IDE Fix pack or DDevextensions that terminates Delphi? Or maybe something else he has loaded is terminating Delphi on him, and he's just not aware of it.
ReplyDeleteWarren Postma Vincent will just be unloading the package in the wrong manner
ReplyDeleteDavid Heffernan Any chance of being helpful instead of just making noise? Clearly Vincent Parrett isn't doing something correct but just saying "is not unloading properly" is just adding noise to the topic. If is was Stack Overflow, I am sure it would be down voted.
ReplyDeleteIf you know how to unload properly, then suggest it - be helpful. :)
Nicholas Ring If this was Stack Overflow the question would have been closed as off-topic, cannot reproduce without MCVE. The onus is on Vincent to explain how he is unloading packages. The documentation explains how to do it:
ReplyDeletehttp://docwiki.embarcadero.com/RADStudio/en/Loading_Packages_with_the_LoadPackage_Function
Call LoadPackage to load and, well, UnloadPackage to unload. It's that simple really. Until Vincent offers up more, there's nothing more to say.
And this is what is so poor about Google+ for this type of question. Vincent has perhaps moved on. But people here are still guessing and trying to solve the problem, a non-problem.
David Heffernan
ReplyDeleteThanks David, you were faster than me.
Comment removed.
Udo Sommer I don't about others but the link you provided was interesting to me. Thanks
ReplyDeleteDavid Heffernan I haven't moved on, I just went home and went to bed.. (I'm down under).
ReplyDeleteThanks for the replies, I suspect it does have something to do with unloading packages, since we do have the scenario mentioned in the SO link that Udo Sommer provided... the exe references our core api package, but also loads other packages that reference that core package.
Vincent Parrett Well that's it. If you don't unload 'em, they won't be finalized. Case closed.
ReplyDeleteDavid Heffernan Have you asked Vincent for more information? I have not seen that request here but I see it frequently in SO
ReplyDeleteSO has these types of questions but they usually get closed off by (IMO) over-zealous moderators. And that is what is good with G+ - you can have some fun (within limitations) but in the end it is all about helping each other (and points don't matter) :)
Ok, so I just checked the code and we do unload the packages (, and I see them being unloaded in the debugger event log.
ReplyDeleteNicholas Ring
ReplyDeleteI don't want to be offending, but if someone asks for help, she/he should provide as much information as possible by her-/himself.
We are so kind to think about problems of other people, invest time and try to provide solutions.
Analogue to SO.
I think David Heffernan is right in his opinion. He is willing to help - but why go further, when he/we has/have to ask questions that should be/are already answered?
I know, it seems to be rude (as criticised by many people concerning SO), but what if you see this day to day?
It's a good feeling to be helpful - for sure!
But on the other hand, if the answer and a pointer to the right direction are already there (like on SO), why not say so?
+Nicholas All Vincent has to do is show how to reproduce the issue.
ReplyDeleteUdo Sommer I totally agree with you that when someone asks for help, as much information should be provided. However, there are two sides to this - providing too much information just muddy the waters, so to speak and when you remove information, you might remove a crucial piece... So sometimes you need to ask.
ReplyDeleteBut G+ goes beyond SO. If it didn't, I would be able to post what I attended last Thursday (https://plus.google.com/u/0/116430453567926016001/posts/Vb9cEC3pY4r) and all the tidbits of information I gathered from it.
My issue with David Heffernan is that he only said "Vincent will just be unloading the package in the wrong manner". How is that helpful? How did David come to that conclusion without extra information? It has only came to light now that it seems that Vincent is unloading but the destructors are still not being executed.
And what happens is it is a regression bug? Even if SO has the correct answer at the time of positing the question (which is close to four years ago) it doesn't mean it is not a bug now..?
Please don't get me wrong. Posting possible answers is good (and in this case, I found your link interesting) but SO information can be out of date and need to be validated before committing to it.
David Heffernan Maybe it is propriety software that he can't easily...? And all you have to do is ask too. :)
ReplyDeleteNicholas Ring If Vincent was unloading properly, with UnloadPackage, then the finalization code would run. That's how packages work. Vincent is a very experienced and competent Delphi developer. I don't think I need to explain that to him. Or perhaps there is a Delphi bug. In which case an MCVE should be created and submitted as a bug report. Vincent knows all this I am quite sure.
ReplyDeleteDavid Heffernan Udo Sommer You seem to think I'm reporting a bug here, all I asked was for a reference to any info on how/when class constructors/destructors work.. since they were not working for me in this instance. I'm not sure why you think I need to provide a reproducable case here... it's not like I screamed Bug!!!!
ReplyDeleteNicholas Ring
ReplyDeleteIf it would be a regression bug, we need at least to know a Delphi version to tell him, that we tested it with what we are able to try and that it works in our cases, or even not.
To come to your point, it is important to know what to tell and what to ask if problems occur. It is some sort of an art, but we are scientists and I think all of us (in these thread) are able to spot and precise problems.
Vincent Parrett
If done right, they work for packages. Concerning pure Delphi DLLs, you can get into trouble.
If you need more input, feel free to write me a message. I will collect some info for you.
Vincent Parrett Which is why I was not pestering. It's Nicholas Ring that seems agitated. We already established how class destructors work, as described by the documentation. And so we can discern that you are not properly unloading the package. Beyond that, we can't say much and there's little point in anyone guessing. Which was my point.
ReplyDeleteNot sure what else I am supposed to do to unload my packages though.. I loop through the list of packages that I loaded (for which I store the handle) and call unloadpackage.. is there more to it to "properly" unload packages?
ReplyDelete+Vincent Nope, that's it. When you do that, the package is finalized. Its unit finalization sections are run. Easy enough to check with a vanilla package. You need to work out why that's not happening for you.
ReplyDeleteI just disabled all dynamically loaded packages and my core package was finalized properly.. then re-enabled a few packages and it still finalizes... so now to go through the 70 odd packages and figure out which one is causing the problem.. ;(
ReplyDeleteAre there interdependencies between any of the packages? Is it an order of events issue?
ReplyDeleteOk, cause identified. Turns out there is a package which is dynamically loading another package, that other package isn't being unloaded.. thanks for the pointers folks.
ReplyDeleteDavid was very helpful. Knowing boatloads is indeed helpful.
ReplyDelete