Lifecycle of a custom plugin

Hello everyone,

I’m currently writing a plugin with a custom rule.
In this rule I load a lot of things in memory that are not freed automatically.

My question is: Writing a rule that extends the IssuableSubscriptionVisitor class, is there a place in my plugin where I’m sure the rule parsing is complete so I can free up memory?

The thing is that I noticed that there is the leaveFile method which launches when the analysis leaves the file but I’m afraid that each time I have to load my data then free it with the leaveFile, then recharge them etc.

Isn’t there a way or a method all at the end of my rule or all the rules to free up memory?

In addition, can someone explain me how the plugin lifecycle works during a scan? which files and/or methods come into play?

Best regards,