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.

Comments

  1. out of curiosity, do the class constructors get called?

    ReplyDelete
  2. That'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?

    ReplyDelete
  3. According 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.

    ReplyDelete
  4. 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.

    ReplyDelete
  5. David 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"

    Still not fixed in #10Seattle

    ReplyDelete
  6. Leif Uneus Hmm, that sounds familiar ....

    ReplyDelete
  7. David Heffernan Indeed, since you reported the issue :-)

    ReplyDelete
  8. Is 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?

    ReplyDelete
  9. Warren Postma It's well known that properly unloaded packages finalize their units. No need for any fix packs. Clearly Vincent is not unloading properly.

    ReplyDelete
  10. Doesn'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.

    ReplyDelete
  11. Warren Postma Vincent will just be unloading the package in the wrong manner

    ReplyDelete
  12. David 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.

    If you know how to unload properly, then suggest it - be helpful. :)

    ReplyDelete
  13. 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: 

    http://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.

    ReplyDelete
  14. David Heffernan​
    Thanks David, you were faster than me.

    Comment removed.

    ReplyDelete
  15. Udo Sommer I don't about others but the link you provided was interesting to me. Thanks

    ReplyDelete
  16. David Heffernan  I haven't moved on, I just went home and went to bed.. (I'm down under). 

    Thanks 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.

    ReplyDelete
  17. Vincent Parrett  Well that's it. If you don't unload 'em, they won't be finalized. Case closed.

    ReplyDelete
  18. David Heffernan Have you asked Vincent for more information? I have not seen that request here but I see it frequently in SO

    SO 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) :)

    ReplyDelete
  19. Ok, so I just checked the code and we do unload the packages (, and I see them being unloaded in the debugger event log.

    ReplyDelete
  20. Nicholas Ring​​
    I 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?

    ReplyDelete
  21. +Nicholas All Vincent has to do is show how to reproduce the issue.

    ReplyDelete
  22. Udo 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.

    But 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.

    ReplyDelete
  23. David Heffernan Maybe it is propriety software that he can't easily...? And all you have to do is ask too. :)

    ReplyDelete
  24. Nicholas 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.

    ReplyDelete
  25. David 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!!!!

    ReplyDelete
  26. Nicholas Ring
    If 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.

    ReplyDelete
  27. 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.

    ReplyDelete
  28. Not 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
  29. +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.

    ReplyDelete
  30. I 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.. ;(

    ReplyDelete
  31. Are there interdependencies between any of the packages? Is it an order of events issue?

    ReplyDelete
  32. Ok, 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.

    ReplyDelete
  33. David was very helpful. Knowing boatloads is indeed helpful.

    ReplyDelete

Post a Comment