Quote from IStopListener interface's JavaDoc comment:
Quote:
There is no specific moment when it is known that some indicator instance is not used anymore,
so onStop() method will be called when this instance became unreachable through strong reference (or on application shutdown).
Therefore, it is preferable to not implement IStopListener interface by indicator directly, but use for it static inner class.
Example of such implementation available in attached file.
Indicator's instances are created not only before adding indicator to chart, but also during IIndicators.getIndicator() method call (for using in strategies or another indicator) and in many other cases. IIndicator.onStart() method is called once for each instance after its creation.
So, to ensure that IStopListener.onStop() method will be called only once for each instance and this indicator instance will not be used later, we should know that this instance is unreachable for any other object, even IStopListener implementation object.
Therefore, IStopListener.onStop() method will not be called immediately after indicator deletion from chart, but in some moment in future, when garbage collector detects that there is no references to indicator (or on application shutdown).
Method IStopListener.onStop() is intended to release resources allocated in IIndicator.onStart(), so it should hold references to this resources, but not to indicator instance.
It makes implementation more difficult, but I don't see another possibility to respect above conditions.