@@ -354,31 +354,76 @@ watchEffect(() => {
354354
355355 // Only recreate if key has changed
356356 if (currentKey !== lastPivotDataKey ) {
357- // Properly clean up old instance
357+ // Properly clean up old instance with enhanced cleanup
358358 const oldPivotData = pivotData .value
359359 if (oldPivotData ) {
360- // Deep cleanup to break circular references
360+ // Deep cleanup to break all aggregator closures
361361 if (oldPivotData .tree ) {
362362 for (const rowKey in oldPivotData .tree ) {
363363 for (const colKey in oldPivotData .tree [rowKey ]) {
364364 const agg = oldPivotData .tree [rowKey ][colKey ]
365- // Clear aggregator references
366365 if (agg && typeof agg === ' object' ) {
366+ // Break closure references completely
367367 Object .keys (agg ).forEach (key => {
368- delete agg [key ]
368+ if (typeof agg [key ] === ' function' ) {
369+ agg [key ] = null // Break function closures
370+ } else if (typeof agg [key ] === ' object' && agg [key ] !== null ) {
371+ agg [key ] = null // Break object references
372+ } else {
373+ delete agg [key ] // Delete primitive values
374+ }
369375 })
370376 }
371377 }
372378 delete oldPivotData .tree [rowKey ]
373379 }
374380 }
381+
382+ // Clean up aggregator function references
383+ if (oldPivotData .aggregator ) oldPivotData .aggregator = null
384+
385+ // Clean up row/col totals aggregators
386+ Object .keys (oldPivotData .rowTotals ).forEach (key => {
387+ const agg = oldPivotData .rowTotals [key ]
388+ if (agg && typeof agg === ' object' ) {
389+ Object .keys (agg ).forEach (prop => {
390+ if (typeof agg [prop ] === ' function' || (typeof agg [prop ] === ' object' && agg [prop ] !== null )) {
391+ agg [prop ] = null
392+ }
393+ })
394+ }
395+ delete oldPivotData .rowTotals [key ]
396+ })
397+
398+ Object .keys (oldPivotData .colTotals ).forEach (key => {
399+ const agg = oldPivotData .colTotals [key ]
400+ if (agg && typeof agg === ' object' ) {
401+ Object .keys (agg ).forEach (prop => {
402+ if (typeof agg [prop ] === ' function' || (typeof agg [prop ] === ' object' && agg [prop ] !== null )) {
403+ agg [prop ] = null
404+ }
405+ })
406+ }
407+ delete oldPivotData .colTotals [key ]
408+ })
409+
410+ // Clean up allTotal aggregator
411+ if (oldPivotData .allTotal && typeof oldPivotData .allTotal === ' object' ) {
412+ Object .keys (oldPivotData .allTotal ).forEach (prop => {
413+ if (typeof oldPivotData .allTotal [prop ] === ' function' || (typeof oldPivotData .allTotal [prop ] === ' object' && oldPivotData .allTotal [prop ] !== null )) {
414+ oldPivotData .allTotal [prop ] = null
415+ }
416+ })
417+ }
418+ oldPivotData .allTotal = null
419+
420+ // Clear all remaining properties
375421 oldPivotData .tree = {}
376422 oldPivotData .rowKeys = []
377423 oldPivotData .colKeys = []
378424 oldPivotData .rowTotals = {}
379425 oldPivotData .colTotals = {}
380426 oldPivotData .filteredData = []
381- oldPivotData .allTotal = null
382427 }
383428
384429 // Create new instance
@@ -391,27 +436,73 @@ watchEffect(() => {
391436onUnmounted (() => {
392437 const data = pivotData .value
393438 if (data ) {
394- // Deep cleanup to ensure memory is freed
439+ // Enhanced cleanup: Break aggregator closures completely
395440 if (data .tree ) {
396441 for (const rowKey in data .tree ) {
397442 for (const colKey in data .tree [rowKey ]) {
398443 const agg = data .tree [rowKey ][colKey ]
399444 if (agg && typeof agg === ' object' ) {
445+ // Break closure references completely
400446 Object .keys (agg ).forEach (key => {
401- delete agg [key ]
447+ if (typeof agg [key ] === ' function' ) {
448+ agg [key ] = null // Break function closures
449+ } else if (typeof agg [key ] === ' object' && agg [key ] !== null ) {
450+ agg [key ] = null // Break object references
451+ } else {
452+ delete agg [key ] // Delete primitive values
453+ }
402454 })
403455 }
404456 }
405457 delete data .tree [rowKey ]
406458 }
407459 }
460+
461+ // Clean up aggregator function references
462+ if (data .aggregator ) data .aggregator = null
463+
464+ // Clean up row/col totals aggregators
465+ Object .keys (data .rowTotals ).forEach (key => {
466+ const agg = data .rowTotals [key ]
467+ if (agg && typeof agg === ' object' ) {
468+ Object .keys (agg ).forEach (prop => {
469+ if (typeof agg [prop ] === ' function' || (typeof agg [prop ] === ' object' && agg [prop ] !== null )) {
470+ agg [prop ] = null
471+ }
472+ })
473+ }
474+ delete data .rowTotals [key ]
475+ })
476+
477+ Object .keys (data .colTotals ).forEach (key => {
478+ const agg = data .colTotals [key ]
479+ if (agg && typeof agg === ' object' ) {
480+ Object .keys (agg ).forEach (prop => {
481+ if (typeof agg [prop ] === ' function' || (typeof agg [prop ] === ' object' && agg [prop ] !== null )) {
482+ agg [prop ] = null
483+ }
484+ })
485+ }
486+ delete data .colTotals [key ]
487+ })
488+
489+ // Clean up allTotal aggregator
490+ if (data .allTotal && typeof data .allTotal === ' object' ) {
491+ Object .keys (data .allTotal ).forEach (prop => {
492+ if (typeof data .allTotal [prop ] === ' function' || (typeof data .allTotal [prop ] === ' object' && data .allTotal [prop ] !== null )) {
493+ data .allTotal [prop ] = null
494+ }
495+ })
496+ }
497+ data .allTotal = null
498+
499+ // Clear all remaining properties
408500 data .tree = {}
409501 data .rowKeys = []
410502 data .colKeys = []
411503 data .rowTotals = {}
412504 data .colTotals = {}
413505 data .filteredData = []
414- data .allTotal = null
415506 pivotData .value = null
416507 }
417508})
0 commit comments