1

I am creating an Ajax Client Control in ASP.Net. By inheriting from IScriptControl and then adding the relavant javascript class (which would inherit from a javascript control). I have found a memory leak in the following code:

Type.registerNamespace("mynamespace");

myClass = function (element) {

    myClass.initializeBase(this, [element]);
}

myClass.prototype = {

    initialize: function () {

        myClass.callBaseMethod(this, 'initialize');


        var me = this;

        $(document).ready(function () {

            me._initializeControl();
            me._hookupEvents();

        });

    },

    dispose: function () {
        //Add custom dispose actions here
        myClass.callBaseMethod(this, 'dispose');
    },
//...other code ... 

  _hookupEvents: function () {
        var me = this;
        var e = this.get_element();
        $("#viewRates", e).click(function () {
            me.openDialog();
        });

    },
//...other code... 
myClass.registerClass('myClass', Sys.UI.Control);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

_hoookupEvents is a function in my javascript file. The leak is related ot the line me.openDialog. If I remove this line, there is no leak. However, I need this line to be able to call a function from the class (I cannot just use 'this' in the function because it would refer to the button). Is there a better way to do this? Or maybe I just need to call some methods in the dispose function to clean such things?

4

2 に答える 2

1

myclass のインスタンスが 2 つしかない場合、これをメモリ リークと呼ぶのは非常にためらいます。myclass のインスタンスが 2,000 ある場合、確実にリークがあります。特定の条件で myClass を作成する動的インスタンス化ステートメントを一生懸命探します。それは私がよく目にするものです(アプリケーションの初期化時にループでクラスを作成する、おそらくフォーム送信がインスタンス化をトリガーする可能性があり、複数のオブジェクトを作成するための送信を取得できるかどうかを確認するために完全にQAされていませんでした)。

于 2013-06-03T18:29:01.233 に答える