Is creating objects in initialization section a good idea? I'm experiencing some strange behavior when I'm doing this (runtime errors, av)

Comments

  1. Anthony Frazier When it comes to the VCL, it isn't always a great example to follow. :)

    ReplyDelete
  2. Nicholas Ring Yes, usually it is, especially if you hide the variable in the implementation, and only expose the function, then you get a lazy-initialized singleton.

    The exception is probably when that singleton is going to be used in a multi-threaded environment, as then lazy-initialization needs to be protected by critical section or locks, while an instance created in the initialization section doesn't need them.

    ReplyDelete

Post a Comment