Jump to content
Jacek Laskowski

Spring4D and objects life cycle

Recommended Posts

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×