# What's wrong with NetConnection?

**URL:** <https://forum.kirupa.com/t/whats-wrong-with-netconnection/287155>\
**Category:** Uncategorized\
**Created:** [April 27, 2009, 12:08pm UTC](https://forum.kirupa.com/t/whats-wrong-with-netconnection/287155 "2009-04-27T12:08:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![toojee](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@toojee](https://forum.kirupa.com/u/toojee)\
**Post date:** [April 27, 2009, 12:08pm UTC](https://forum.kirupa.com/t/whats-wrong-with-netconnection/287155/1 "2009-04-27T12:08:10Z")

</div>

Hi ! I’m french I speak a little english, so i write what i can 😃  
I have a problem with garbage collector and NetConnection. I can’t delete NetConnection object of memory and my website become heavy!  
I do a test for show you, my problem :

```auto

private var myService:NetConnection
  //--------------------------------------------------------------------------------------
  //---------------------------------------------------------------Fonction - constructeur
  //--------------------------------------------------------------------------------------
  public function Main():void 
  {
   if (stage) init();
   else addEventListener(Event.ADDED_TO_STAGE, init);
  }
  //--------------------------------------------------------------------------------------
  //------------------------------------------------------------------------Initialisation
  //--------------------------------------------------------------------------------------
  private function init(e:Event = null):void 
  {
   removeEventListener(Event.ADDED_TO_STAGE, init);
   //-------------------------------------------------------
   stage.addEventListener( MouseEvent.MOUSE_DOWN, onStage_Down )
   stage.addEventListener( MouseEvent.MOUSE_UP, onStage_Up )
  }
  //--------------------------------------------------------------------------------------
  //---------------------------------Au mouseDown sur le stage, on lance la boucle de test
  //--------------------------------------------------------------------------------------
  private function onStage_Down(e:MouseEvent):void 
  {
   stage.addEventListener( Event.ENTER_FRAME, onLoop )
  }
  //--------------------------------------------------------------------------------------
  //------------------------------------------------Au mouseUp on stoppe la boucle de test
  //--------------------------------------------------------------------------------------
  private function onStage_Up(e:MouseEvent):void 
  {
   stage.removeEventListener( Event.ENTER_FRAME, onLoop )
  }
  //--------------------------------------------------------------------------------------
  //------------------------------Pendant la boucle, on déclenche le garbage collector et on recréer 
  //--------------------------------------------------------------------------------------
  private function onLoop(e:Event):void 
  {
   myService = null
   System.gc();
   //-------------------------------------------------------   
   myService = new NetConnection()
   myService.connect("http://localhost/Remoting/amfphp/gateway.php")
   myService.close()
   myService = null;
   //-------------------------------------------------------
   trace( System.totalMemory );
  }

```

I use NetConnection with amfphp in my website.  
How its’t possible the Sytem.memory grow up indefinitly?  
Thans for answers with no complicated words 😃
