Jacek Laskowski 57 Posted June 28, 2019 I have a class that does not have an interface, I register it and its factory in this way: TServiceLog = class; TServiceLogFactory = reference to function() : TServiceLog; Container.RegisterType<TServiceLog, TServiceLog>.PerResolve; Container.RegisterFactory<TServiceLogFactory>; pay attention to the use of PerRersolve, maybe it matters. Then I use this class in many other classes, as a parameter in the constructor, all object creation is done by Spring container: TFrameworkSMTPBus = class(TSMTPBus, IFrameworkBase, ISMTPBus) private fServiceLog: TServiceLog; public constructor Create(const aServiceLog: TServiceLog; const aSMTPClientFactory: TSMTPClientFactory); reintroduce; virtual; end; Are TServiceLog instances automatically released by Spring or should I release manually? It looks like it is released by Spring, but I have one case of memory leak, where after adding fServiceLog.Free leaked disappeared. And that's why I ask how it works underneath. Share this post Link to post
Hallvard Vassbotn 3 Posted June 28, 2019 Use the source and the debugger? For instance, set a breakpoint in your destructor and see if and from where (stack trace) it is triggered. Share this post Link to post
Jacek Laskowski 57 Posted June 29, 2019 I'm asking about Spring principles/rules. Because many instances of one of the classes are released by Spring and one of them is not released. I could not get to the cause. Share this post Link to post
Stefan Glienke 2002 Posted June 29, 2019 The only instances the container takes ownership of are singletons Share this post Link to post