backbone.validation icon indicating copy to clipboard operation
backbone.validation copied to clipboard

Backbone.Validation.bind memory leak

Open bigluck opened this issue 11 years ago • 3 comments

Hi everybody, I'm having memory leaks using Backbone.Validation.bind and unbind. If I bind a view and then, before destroy it, I unbind them:

class CountryEditView extends Backbone.View
    initialize: ->
        @parent = @options.parent
        @app = @parent.app
        @listenTo @model, 'change', @change
        @listenTo @model, 'destroy remove', @back

        Backbone.Validation.bind @,
            valid: (view, key) ->
                if ($ele = view.$("[name=#{key}]")).length
                    $ele.closest('.control-group').removeClass 'error'
            invalid: (view, key, error) ->
                if ($ele = view.$("[name=#{key}]")).length
                    $ele.closest('.control-group').addClass 'error'

    remove: ->
        Backbone.Validation.unbind @
        super

Even if the view has been removed using the remove() method, 3 references persist in memory:

  • validate() backbone.validation-0.7.1.js:209
  • isValid() backbone.validation-0.7.1.js:189
  • preValidate() backbone.validation-0.7.1.js:182

Global Blue Admin-1

bigluck avatar Apr 09 '13 08:04 bigluck

Apologies for being a bit out of topic. What's the program you're using to analyse this issue?

kayhadrin avatar May 03 '13 07:05 kayhadrin

I've used the Google Chrome Profiles taking Heap Snapshots

bigluck avatar May 03 '13 08:05 bigluck

@bigluck Hey, did you manage to find a solution?

boycce avatar Jul 04 '14 02:07 boycce