RTMFP Multicast memory leak - feature or bug?
When using a NetGroup in multicast mode with posting enabled, all _net_group.post() messages are never released (aka - they stay in memory forever - see my Scout screenshot below - oddly in the Memory-Other category.)
But, is this a feature of a multicast group (the nodes hold onto all messages so that any new group member will receieve all group messages, even prior to the time it joined the group), or is it a bug?
If it's a feature, this seems like a serious handicap. This means that multicast groups would probably be fine for basic chat (though they'll crash eventually), but if you're sending across large data like images or audio or video, the app will crash in a short amount of time.
Am I missing a setting that would disable this "feature"? Is there a purge interval? Currently I've resorted to destroying and re-creating the group on a timer, which fixes the memory problem, but it makes the communication unreliable.
Code and scout screenshot below. Note that the rate of data doesn't matter, but I've set this to post 2MB every 0.2 seconds (i.e. imagine a screen-cast app), so it crashes on my Android device at 300MB utilized in ~45 seconds:
package
{
import flash.events.NetStatusEvent;
import flash.net.GroupSpecifier;
import flash.net.NetConnection;
import flash.net.NetGroup;
import flash.utils.setInterval;
import flash.utils.clearInterval;
import flash.utils.ByteArray;
import flash.utils.getTimer;
public class MulticastTest
{
protected var _nc:NetConnection;
protected var _ng:NetGroup;
private static var UNIQUE:int = 0;
public function MulticastTest():void
{
setup_network();
// Send 2MB every 0.2 seconds, watch memory in Scout
setInterval(function():void {
if (_ng) { // wait until group created
trace(" Sending 2MB");
// i.e. mimic a large-ish ByteArray, like an image
var b:ByteArray = new ByteArray();
b.length = 2000000;
_ng.post({ byt: b, cc:(UNIQUE++)});
}
}, 200);
}
private function setup_network():void
{
_nc = new NetConnection();
_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
_nc.connect("rtmfp:");
}
protected function netStatus(e:NetStatusEvent):void
{
switch (e.info.code) {
case "NetGroup.Connect.Rejected":
trace("Multicast error, no wifi?");
break;
case "NetGroup.Connect.Success":
trace("Multicast group successfully created! "+getTimer());
break;
case "NetConnection.Connect.Success":
setup_group();
break;
case "NetGroup.Neighbor.Connect":
break;
case "NetGroup.Neighbor.Disconnect":
break;
case "NetGroup.Posting.Notify":
break;
}
}
protected function setup_group():void
{
var groupspec:GroupSpecifier = new GroupSpecifier("test/test");
groupspec.postingEnabled = true;
groupspec.ipMulticastMemberUpdatesEnabled = true;
groupspec.addIPMulticastAddress("225.225.0.1:38745");
trace("Setting up multicast group...");
_ng = new NetGroup(_nc, groupspec.groupspecWithAuthorizations());
_ng.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
}
}
}

