Skip to main content
Participant
April 16, 2013
Question

Why does a closed NetConnection that has no event listeners or references stick around in memory?

  • April 16, 2013
  • 1 reply
  • 443 views

It seems that if flash.net.NetConnection is instantiated and connected to an HTTP URL (such as an AMFPHP gateway), that instance is never picked up by garbage collection even after it has been closed and the only reference is set to null.

On the other hand, if the instance is connected to null (as would be done when used to play video/mp3 files), the instance is cleared from memory.

To clarify, the following connection will stick around in memory:

var stickyConn:NetConnection = new NetConnection();
stickyConn
.connect("http://myserver/amfphp/gateway.php");
stickyConn
.close(); stickyConn = null;

Whereas, the following connection will be cleared from memory immediately:

var tempConn:NetConnection = new NetConnection();
tempConn
.connect(null);

tempConn.close();

tempConn = null;

Some things I have already tried to solve this issue:

  • set the client to an empty object (since the default value of the client is the NetConnection itself)
  • before closing the connection, call connect(null)
  • after closing the connection, call connect(null) and close it again

Has anyone run into this issue before? Is there a solution to this?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 16, 2013

1. are you defining a netstream?

2. how do you know stickyConn is not cleared from memory?

Participant
April 16, 2013

I am not defining a NetStream, as it is not necessary for AMFPHP communication.

I know for a fact that stickyConn is not cleared from memory because I am using a profiler that shows me how many objects of each type are still in memory (and I am able to view where/when each instance was instantiated)