Monday, March 22, 2010

Memory Leak In DataService

Hi All,

聽聽聽聽聽 I had posted this query to couple of other groups ..I am still struglling with this issue..Hope someone聽 will聽 help me out here


聽聽聽聽聽 I have聽 very basic application which uses聽 DataSerives over RTMP channel聽 to populate dataGrid , I have not used any聽 user defined component.

This application has got LOAD data and Remove data聽 Button just to simulate the actual application

What happens , when I click on LOAD data , It聽 loads the data from server(JBOSS) then I Remove all the data and force the GC to run

If I continuously keep loading and removing the聽 data ,聽 memory goes up every time and after some times It reaches to threshold and聽 finally crashes the Browser.

In actual application as soon as user logs in a dedicated DS destination is created..

聽聽聽 private function createDestination(destName:String):void{
聽聽聽聽聽聽聽聽聽聽聽聽 var remoteService:RemoteObject = new RemoteObject(''DestinationManager'');
聽聽聽聽聽聽聽聽聽聽聽聽 remoteService.addEventListener(ResultEvent.RESULT, resultHandler,false,0,true);
聽聽聽聽聽聽聽聽聽聽聽聽 var operation:AbstractOperation = remoteService.getOperation(''createDestination'');
聽聽聽聽聽聽聽聽聽聽聽聽 operation.send(destName);
聽聽聽聽聽聽聽聽聽聽聽聽 var cs:ChannelSet = new ChannelSet();
聽聽聽聽聽聽聽聽聽聽聽聽 var rtmpChannel:RTMPChannel = ServerConfig.getChannel(''my-rtmp'') as聽 RTMPChannel;
聽聽聽聽聽聽聽聽聽聽聽聽 cs.addChannel(rtmpChannel);
聽聽聽聽聽聽聽聽聽聽聽聽 tradeService = new DataService() ;
聽聽聽聽聽聽聽聽聽聽聽聽 tradeService.destination=destName;
聽聽聽聽聽聽聽聽聽聽聽聽 tradeService.channelSet = cs;聽聽
聽聽聽聽聽聽聽聽 }



Now when user hits on Load data button to load the trade data ...

聽聽 public function loadData():void
聽聽聽聽聽聽聽聽 {聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽 var remoteService:RemoteObject聽 = new RemoteObject(''filterRemoteVO'');
聽聽聽聽聽聽聽聽 var operation:AbstractOperation = remoteService.getOperation(''loadData'');
聽聽聽聽聽聽聽聽 tradeService.fill(tradeCollection);
聽聽聽聽聽聽聽聽 operation.send(rowData.text ,GUIID);
聽聽聽聽聽聽聽聽 tradeList.dataProvider = tradeCollection;
聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽 }聽聽

聽聽聽

Remove Data聽 hit I clean all the resource and released collection :-

聽聽 聽聽 public聽 function聽 removeAll():void{
聽聽聽聽聽聽聽聽 if(tradeList.dataProvider){
聽聽聽聽聽聽聽聽聽聽聽聽聽 tradeCollection.source = new Array();
聽聽聽聽聽聽聽聽聽聽聽聽聽 tradeList.dataProvider.source = new Array();
聽聽聽聽聽聽聽聽聽聽聽聽聽 tradeList.dataProvider = null;
聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽 tradeService.release();
聽聽聽聽聽聽聽聽聽聽 tradeService.releaseCollection(tradeCollection);
聽聽聽聽聽聽聽聽聽 tradeService.channelSet.disconnectAll();
聽聽聽聽聽聽聽聽聽 tradeService.disconnect();
聽聽聽聽聽聽聽聽聽聽 tradeService.logout();
聽聽聽聽聽聽聽聽聽聽 System.gc();
聽聽聽聽聽聽聽聽 }


Except these 3 function I don't have any code which could cause memory leak.

I m using

  • LCDS 2.5
  • Flex 3.0
  • JBoss4.2


Please see the mxml file below聽聽 , If聽 possible please have a look at it , I might聽 not be using dataSerice API correctly.

I have been trying to solve this leak for last two week , I really need help from you guys.
My client has already evaluating other contemporary technology because of this memory issue.

I have also created scalled down war file which can be deployed on any聽 java application server.

Any help will greatly be appreciated

Regards,

Dam
######################## MXML##########################


%26lt;?xml version=''1.0'' encoding=''utf-8''?%26gt;
%26lt;mx:Application xmlns:mx=''http://www.adobe.com/2006/mxml'' layout=''absolute''
聽聽聽聽聽 creationComplete=''init();'' height=''100%'' width=''100%''
聽聽聽聽 %26gt;
聽聽聽聽 %26lt;mx:Script %26gt;
聽聽聽聽 %26lt;![CDATA[
聽聽聽聽聽聽聽聽 import mx.containers.GridRow;
聽聽聽聽聽聽聽聽聽聽 import mx.utils.Base64Decoder;
聽聽聽聽聽聽聽聽 import mx.utils.StringUtil;
聽聽聽聽聽聽聽聽聽聽聽 import mx.events.CollectionEvent;
聽聽聽聽聽聽聽聽 import mx.formatters.Formatter;
聽聽聽聽聽聽聽聽 import mx.events.ResizeEvent;
聽聽聽聽聽聽聽聽 import mx.controls.DataGrid;
聽聽聽聽聽聽聽聽 import mx.effects.Fade;
聽聽聽聽聽聽聽聽 import mx.events.DataGridEvent;
聽聽聽聽聽聽聽聽 import mx.utils.ObjectUtil;
聽聽聽聽聽聽聽聽 import mx.events.ScrollEvent;
聽聽聽聽聽聽 import mx.formatters.DateFormatter;
聽聽聽聽聽聽 import mx.events.ListEvent;
聽聽聽聽聽聽 import mx.data.mxml.DataService;
聽聽聽聽聽聽 import mx.messaging.config.ServerConfig;
聽聽聽聽聽聽 import mx.messaging.channels.RTMPChannel;
聽聽聽聽聽聽 import mx.messaging.ChannelSet;
聽聽聽聽聽聽 import mx.rpc.AbstractOperation;
聽聽聽聽聽聽 import mx.rpc.remoting.RemoteObject;
聽聽聽聽聽聽 import mx.collections.ArrayCollection;
聽聽聽聽聽聽 import mx.controls.Alert;
聽聽聽聽聽聽 import mx.rpc.events.ResultEvent;
聽聽聽聽聽聽 import mx.messaging.messages.*;
聽聽聽聽聽聽 import mx.messaging.events.*;
聽聽聽聽聽聽 import mx.controls.Alert;



聽聽聽聽聽聽聽 private var GUIID:String;
聽聽聽聽聽聽聽 private var lastRollOverIndex:Number;
聽聽聽聽
聽聽聽聽聽聽聽 public var tradeService:DataService=null;
聽聽聽聽聽聽聽 public var tradeCollection:ArrayCollection = new ArrayCollection();

聽聽聽聽聽聽 public var flag:Boolean = false;
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽
聽聽聽聽聽聽聽 private function init():void {
聽聽聽聽聽聽聽聽聽聽 var guiId:String =''TEST'';
聽聽聽聽聽聽聽聽聽聽聽 createDestination(GUIID);
聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽 }

聽聽聽聽聽聽聽 public function getData():void{
聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽 // memory.text =''''+ ((System.totalMemory / 1024)/1024);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 public function releaseDataServices():void {
聽聽聽聽聽聽聽聽聽聽 //聽 tradeService.fill(null);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 tradeService.release();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 // tradeService.releaseCollection(tradeCollection);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 tradeService.channelSet.disconnectAll();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 tradeService.disconnect();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 tradeService.logout();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //tradeService.dataStore = null;
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /*Function for creating destination*/
聽聽聽聽聽聽聽聽聽 private function createDestination(destName:String):void{
聽聽聽聽聽聽聽聽聽聽聽聽 var remoteService:RemoteObject = new RemoteObject(''DestinationManager'');
聽聽聽聽聽聽聽聽聽聽聽聽 remoteService.addEventListener(ResultEvent.RESULT, resultHandler,false,0,true);
聽聽聽聽聽聽聽聽聽聽聽聽 var operation:AbstractOperation = remoteService.getOperation(''createDestination'');
聽聽聽聽聽聽聽聽聽聽聽聽 operation.send(destName);
聽聽聽聽聽聽聽聽聽聽聽聽 var cs:ChannelSet = new ChannelSet();
聽聽聽聽聽聽聽聽聽聽聽聽 var rtmpChannel:RTMPChannel = ServerConfig.getChannel(''my-rtmp'') as RTMPChannel;
聽聽聽聽聽聽聽聽聽聽聽聽 cs.addChannel(rtmpChannel);
聽聽聽聽聽聽聽聽聽聽聽聽 tradeService = new DataService() ;
聽聽聽聽聽聽聽聽聽聽聽聽 tradeService.destination=destName;
聽聽聽聽聽聽聽聽聽聽聽聽 tradeService.channelSet = cs;聽聽
聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽 //This function calls dataservice fill method depending on wheather destination is created or not
聽聽聽聽聽聽聽 private function resultHandler(event:ResultEvent):void{
聽聽聽聽聽聽聽聽聽聽 //call data service as destination is created successfully
聽聽聽聽聽聽聽聽聽聽聽 var status:Boolean = event.result as Boolean
聽聽聽聽聽聽聽聽聽聽 // Alert.show(''status=''+status);
聽聽聽聽聽聽聽聽聽聽聽 if(status){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽 getData();
聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽 else{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //TODO report error to MATS app聽聽
聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 }
聽聽聽聽聽 public聽 function聽 removeAll():void{
聽聽聽聽聽聽聽聽 if(tradeList.dataProvider){
聽聽聽聽聽聽聽聽聽聽聽聽聽 tradeCollection.source = new Array();
聽聽聽聽聽聽聽聽聽聽聽聽聽 tradeList.dataProvider.source = new Array();
聽聽聽聽聽聽聽聽聽聽聽聽聽 tradeList.dataProvider = null;
聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽 tradeService.release();
聽聽聽聽聽聽聽聽聽聽 // tradeService.releaseCollection(tradeCollection);
聽聽聽聽聽聽聽聽聽 tradeService.channelSet.disconnectAll();
聽聽聽聽聽聽聽聽聽 tradeService.disconnect();
聽聽聽聽聽聽聽聽聽聽 tradeService.logout();
聽聽聽聽聽聽聽聽聽聽 System.gc();
聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽 public function loadData():void
聽聽聽聽聽聽聽聽 {聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽 var remoteService:RemoteObject聽 = new RemoteObject(''filterRemoteVO'');
聽聽聽聽聽聽聽聽 var operation:AbstractOperation = remoteService.getOperation(''loadData'');
聽聽聽聽聽聽聽聽 tradeService.fill(tradeCollection);
聽聽聽聽聽聽聽聽 operation.send(rowData.text ,GUIID);
聽聽聽聽聽聽聽聽 tradeList.dataProvider = tradeCollection;
聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽 }聽聽
聽聽聽
聽聽 ]]%26gt;
%26lt;/mx:Script%26gt;


聽聽聽聽聽 %26lt;mx:DataGrid聽聽 id=''tradeList''
聽聽聽聽聽聽聽聽聽聽聽聽 initialize=''tradeList.dataProvider = tradeCollection'' horizontalScrollPolicy=''auto''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 height=''659'' x=''0'' y=''84''%26gt;
聽聽
聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:columns%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Security Description'' dataField=''securityDesc''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''B/S'' dataField=''transactionType''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Amount'' dataField=''amount''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Price Text'' dataField=''priceText''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Counterparty'' dataField=''counterParty''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Trade Date'' dataField=''tradeDate''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Settle Date'' dataField=''settleDate''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Trade Status'' dataField=''tradeStatusId''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Trader'' dataField=''trader''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Salesperson'' dataField=''salesperson''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Ticket Number'' dataField=''tradeNumber''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Entry Date'' dataField=''tradeTime''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Cancel Date'' dataField=''cancelDate''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:DataGridColumn聽 headerText=''Cancel Time'' dataField=''cancelTime''
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 /%26gt;



聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;/mx:columns%26gt;
聽聽聽聽聽聽聽聽聽 %26lt;/mx:DataGrid %26gt;
聽聽聽聽聽聽聽聽 %26lt;mx:Grid x=''149'' y=''23'' width=''995''%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:GridRow width=''100%'' height=''100%''%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:GridItem width=''100%'' height=''100%''%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:Label text=''Enter No of obejcts''聽聽 width=''111''/%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;/mx:GridItem%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:GridItem width=''100%'' height=''100%''%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:TextInput name=''row'' id=''rowData''聽聽 width=''97''/%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;/mx:GridItem%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:GridItem width=''100%'' height=''100%''%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:Button聽 label=''Load Data'' click='loadData()'/%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;/mx:GridItem%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:GridItem width=''100%'' height=''100%''%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:Button聽 label=''removeAll'' click='removeAll()'/%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;/mx:GridItem%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:GridItem width=''100%'' height=''100%''%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:Label text=''Total Memory''/%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;/mx:GridItem%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:GridItem width=''100%'' height=''100%''%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:TextInput text=''Total Memory'' id=''memory''聽聽 width=''97''/%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;/mx:GridItem%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:GridItem width=''100%'' height=''100%''%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:Label text=''Grid Row Count''/%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;/mx:GridItem%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:GridItem width=''100%'' height=''100%''%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;mx:TextInput name=''GridRowCountN'' id=''GridRowCount''聽聽 width=''97''/%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;/mx:GridItem%26gt;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 %26lt;/mx:GridRow%26gt;



聽聽聽聽聽聽聽聽 %26lt;/mx:Grid%26gt;
聽聽聽

%26lt;/mx:Application%26gt;

Memory Leak In DataService

Hi,

try to call removeEventListener(...) for all objects you created and set eventListeners.

Write about results.

Memory Leak In DataService

Hi Natasha,

Sorry for late reply.

聽聽聽聽聽 I tried your suggestion but It did not help to release memory. Actully,this app contains only one event handler which is for remote method call , I dont think this could cause any memory leak.

Profiling session reveals that It is the issue of DataService class.I dont know How do I convince聽 Adobe to investigate this issue.

Regards,

Dharmendra

No comments:

Post a Comment