Having some confusion about a pattern I’m using to structure my application. The conversation started yesterday in the chat, but thought it’d be cleaner and more helpful to have this as a forum post.
I’m creating a
Context class used as process with state output to distribute it to several places in my app. This
Context class contains in turn an instance of a
NetworkContext that holds all network related stuff (ports, endpoints, etc).
The “bug” I witnessed yesterday was the following : in my
NetworkContext, I have an
OSCServer assigned to
Create which prints all received messages to the
Console in a
ForEach (Reactive). This is for initial debug purposes only. If I did not call dispose on the
NetworkContext, I noticed that an old instance of
NetworkContext would stick around between restarts : if I changed a port number (
Local UDP Port pin), the new port would not be picked up. If I changed the message printed to the Console, the one that was there when vvvv first started would always be there, even between F9.
As @Elias suggested, calling Dispose on the
Network Context as shown in the first screenshot seems to be the way to solve the issue, as now the changes made in
NetworkContext are correctly picked up.
Two questions :
- Why would I have to do that manually? Why would I want an old instance to stick around? I would have assumed VL does that automatically.
- It’s not clear to me “how” I should dispose those instances. I would have assumed I had to call
Dispose (IDisposable)and assign it to
Dispose, but if I do that, I get an error only when I restart my patch :
When going inside
Context, no particular error are shown. I ended up just creating a
Dispose operation in my classes and call that from the outside, which seems to do the trick, but I don’t really understand why.
That was a long one :) Thanks in advance for your enlightenment!