11import $ from 'jquery' ;
2+ import domAdapter from '__internal/core/m_dom_adapter' ;
23import eventsEngine from 'common/core/events/core/events_engine' ;
34import keyboardMock from '../../helpers/keyboardMock.js' ;
45import registerEvent from 'common/core/events/core/event_registrator' ;
@@ -568,7 +569,7 @@ QUnit.test('removeEventListener should not be called if native handler is not ex
568569 delListener . restore ( ) ;
569570} ) ;
570571
571- QUnit . module ( 'Memory' ) ;
572+ QUnit . module ( 'Memory bugs ' ) ;
572573
573574QUnit . test ( 'removing subscriptions should remove data from elementDataMap' , function ( assert ) {
574575 const div = document . createElement ( 'div' ) ;
@@ -591,6 +592,33 @@ QUnit.test('removing subscriptions should not remove data from elementDataMap if
591592 assert . equal ( eventsEngine . elementDataMap . has ( div ) , hasData ) ;
592593} ) ;
593594
595+ QUnit . test ( 'should not leak memory when subscribing on document and clicking elements (T1307313)' , function ( assert ) {
596+ const clickEventName = 'dxclick' ;
597+ const document = domAdapter . getDocument ( ) ;
598+ const fixture = document . getElementById ( 'qunit-fixture' ) ;
599+
600+ fixture . innerHTML = '<button id="test-element">Test</button>' ;
601+
602+ const testElement = document . getElementById ( 'test-element' ) ;
603+
604+ eventsEngine . on ( document , clickEventName , ( ) => { } ) ;
605+
606+ for ( let i = 0 ; i < 100 ; i ++ ) {
607+ testElement . click ( ) ;
608+ }
609+
610+ const eventData = eventsEngine . elementDataMap . get ( document ) ;
611+
612+ const count = Object . keys ( eventData ) . reduce ( ( res , key ) => res + eventData [ key ] . handleObjects ?. length , 0 ) ;
613+
614+ assert . ok (
615+ eventData ?. length <= 5 ,
616+ `Memory should not leak. Element data: ${ count } , ${ Object . keys ( eventData ) } , ${ eventsEngine . elementDataMap . size } `
617+ ) ;
618+
619+ eventsEngine . off ( document ) ;
620+ } ) ;
621+
594622QUnit . module ( 'Strategy' ) ;
595623
596624QUnit . test ( 'it should be possible to set only one method for strategy' , function ( assert ) {
0 commit comments