为了保障原创作者在本站发表文章的利益, 并维护本站原创的精神, 特声明: RIAShanghai对有以下任何情况之一的文章将不通知作者并直接进行快意删除:
- 非原创, 或者原创但一文多发;
- 各种形式的广告与吹擂;
- 不符合本站文章格式.
欢迎各位读者监督. 谢谢合作. 另: 作为Adobe正式的UG, 我们将把Adobe不定期分发的软件,书籍及各种纪念品赠送给发文活跃的作者, 共同进步.
It seems that I am really paranoid to fight memory leaks. Indeed. Here is another one.
Problem description
Assume we have the following function and there is no event listeners registered to the remote object. The entities in the query result should be eligible for garbage collection as soon as the the result arrives.
function executeSqlAndForget():int {
remoteObject.select("SELECT e FROM Entity e");
}However, the entities will stay in memory even after garbage collection is run.
The cause of the problem
remoteObject.select() results creating or re-using an existing mx.rpc.Operation, and this Operation caches the last result (mx.rpc.AbstractInvoker._result). So unless you execute another call to the same operation on the same remote object this last result will hang there and not available for garbage collection.
The solution
You simply clear the last result using:
remoteObject.getOperation("select").clearResult();
Memory leaks may happen anywhere. Just be sensitive. Otherwise, do not blame Adobe for ridiculous memory usage and unexpected crash.