# Is it necessary to remove manually the IMediaStreamActionNotify from the stream?

**URL:** <https://community.wowza.com/t/is-it-necessary-to-remove-manually-the-imediastreamactionnotify-from-the-stream/42708>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [September 20, 2014, 5:20pm UTC](https://community.wowza.com/t/is-it-necessary-to-remove-manually-the-imediastreamactionnotify-from-the-stream/42708 "2014-09-20T17:20:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/system/32/447_2.png) [@system](https://community.wowza.com/u/system)\
**Post date:** [September 20, 2014, 5:20pm UTC](https://community.wowza.com/t/is-it-necessary-to-remove-manually-the-imediastreamactionnotify-from-the-stream/42708/1 "2014-09-20T17:20:43Z")

</div>

Hi,

I have found an example in which an instance of IMediaStreamActionNotify is attached to a stream. In that code there is a code snippet like this:

```auto
public void onStreamDestroy(IMediaStream stream) {
		IMediaStreamActionNotify actionNotify = null;
		WMSProperties props = stream.getProperties();
		synchronized(props)
		{
			actionNotify = (IMediaStreamActionNotify)stream.getProperties().get("streamActionNotifier");
		}
		if (actionNotify != null)
		{
			stream.removeClientListener(actionNotify);
		}
	}

```

Question: if the stream is going to be destroyed, is it really necessary to manually remove this listener? I have never seen any API where this was necessary in order to prevent memory leak. In the generated javadoc that is usually referred to as server side API documentation, I haven’t found any info about this. 🙂

Can you tell it to me? Thanks!

---

<div class="post-metadata">

**Author:** ![Andrew\_Kennedy1](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@Andrew\_Kennedy1](https://community.wowza.com/u/Andrew_Kennedy1)\
**Post date:** [September 23, 2014, 4:24am UTC](https://community.wowza.com/t/is-it-necessary-to-remove-manually-the-imediastreamactionnotify-from-the-stream/42708/2 "2014-09-23T04:24:06Z")

</div>

Hi,

It best practice where possible to remove any objects used in a connection prior to it shutting down. Keeping track of objects used is an important element when writing any code, regardless of language used.

Andrew.

---

<div class="post-metadata">

**Author:** ![Shoo\_Kyuk\_Wei](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@Shoo\_Kyuk\_Wei](https://community.wowza.com/u/Shoo_Kyuk_Wei)\
**Post date:** [October 8, 2014, 5:22pm UTC](https://community.wowza.com/t/is-it-necessary-to-remove-manually-the-imediastreamactionnotify-from-the-stream/42708/3 "2014-10-08T17:22:27Z")

</div>

lol good question 😃 u probably can see memory leak if it doesn’t. Waiting for ur finding!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/system/32/447_2.png) [@system](https://community.wowza.com/u/system)\
**Post date:** [September 25, 2014, 4:21pm UTC](https://community.wowza.com/t/is-it-necessary-to-remove-manually-the-imediastreamactionnotify-from-the-stream/42708/4 "2014-09-25T16:21:04Z")

</div>

Ok, so if we are supposed to do this, that means behind the scenes the IMediaStream object is not garbage collected along with its properties when the client is disconnected. Otherwise we could rely on the GC. Does that mean it’s not safe to expect that a fresh IMediaStream’s properties might contain outdated garbage data from previous cycles?

Thanks!
