Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

IStopListenerOnStop deprecate?
 Post subject: IStopListenerOnStop deprecate? Post rating: 0   New post Posted: Tue 24 Nov, 2015, 20:09 
User avatar

User rating: 0
Joined: Wed 29 May, 2013, 04:14
Posts: 62
I was trying to do that but you can not. Can you suggest a similar solution?

https://www.dukascopy.com/wiki/#IStopListenerOnStop


 
 Post subject: Re: IStopListenerOnStop deprecate? Post rating: 0   New post Posted: Thu 14 Jul, 2016, 13:14 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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.


 

Jump to:  

  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com