Hello,
Yes, TObjectManager is not thread-safe and you should have one TObjectManager per thread. You do not need to use a pool (and shouldn't) since creating the manager is very lightweight and it keeps references to objects in memory, so better create and destroy one in each thread.
And are the objects themselves threadsafe or should each thread fetch its own data? Or can they be shared among threads? You mention that the Object manager keeps references to objects in memory. That would suggest that another objectmanager in another thread shouldn't be touching/using the same objects. That might turn into a memory hog on bigger systems with lots of users and/or big datasets. Why is the ObjectManager keeping references to the created objects?
The objects are not thread safe, and shouldn't be. It's not a memory hog, not more than using TDataset for example. TObjectManager is analog to TDataset. You open, retrieve data, once you're done with it, release it. There is no need to keep objects in TObjectManager (or even a TObjectManager alive) for too long. The objects are kept in memory for memory management (since the TObjectManager creates objects and its associations, so it's easier if it release them automatically) and also for state management (so in an update operation it knows what changed in the object, comparing the state loaded from the database and the state before updating the database).
Tnx that clarifies it!
Hi Wagner,
IDBConnection should not be shared. You should also create one per thread, or at least create a pool so you can reuse them, but only one thread at time can use the IDBConnection.