Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak found with Memlab #20

Open
sbstnplcn opened this issue Mar 13, 2024 · 0 comments
Open

Memory leak found with Memlab #20

sbstnplcn opened this issue Mar 13, 2024 · 0 comments

Comments

@sbstnplcn
Copy link

Hello, I'm experiencing a memory leak with my implementation of Piwik Pro.
I use Node v20.10.0 and Nuxt 2.17.3.

I've copy-paste and adapt to a no-ts env the code found in your core folder to a nuxt plugin, this is my code :

export default ({ env }) => {
  const containerId = env.PIWIK_CONTAINER_ID
  const containerUrl = env.PIWIK_CONTAINER_URL

  if (!containerId) {
    console.error('Empty tracking code for Piwik Pro.')
    return
  }

  if (!containerUrl) {
    console.error('Empty tracking URL for Piwik Pro.')
    return
  }

  if (!document) {
    console.error(
      'Was not possible to access Document interface. Make sure this module is running on a Browser w/ access do Document interface.'
    )
  }

  if (!document || typeof document.createElement !== 'function') {
    console.error(
      'Was not possible to access Document interface. Make sure this module is running on a Browser w/ access do Document interface.'
    )
    return
  }

  let s
  try {
    s = document.createElement('script')
  } catch (error) {
    console.error(
      'Was not possible to access Document interface. Make sure this module is running on a Browser w/ access do Document interface.'
    )
    return
  }

  s.async = true

  s.text = `(function(window, document, dataLayerName, id) {
window[dataLayerName]=window[dataLayerName]||[],window[dataLayerName].push({start:(new Date).getTime(),event:"stg.start"});var scripts=document.getElementsByTagName('script')[0],tags=document.createElement('script');
function stgCreateCookie(a,b,c){var d="";if(c){var e=new Date;e.setTime(e.getTime()+24*c*60*60*1e3),d="; expires="+e.toUTCString();f="; SameSite=Strict"}document.cookie=a+"="+b+d+f+"; path=/"}
var isStgDebug=(window.location.href.match("stg_debug")||document.cookie.match("stg_debug"))&&!window.location.href.match("stg_disable_debug");stgCreateCookie("stg_debug",isStgDebug?1:"",isStgDebug?14:-1);
var qP=[];dataLayerName!=="dataLayer"&&qP.push("data_layer_name="+dataLayerName),isStgDebug&&qP.push("stg_debug");var qPString=qP.length>0?("?"+qP.join("&")):"";
tags.async=!0,tags.src="${containerUrl}/"+id+".js"+qPString,scripts.parentNode.insertBefore(tags,scripts);
!function(a,n,i){a[n]=a[n]||{};for(var c=0;c<i.length;c++)!function(i){a[n][i]=a[n][i]||{},a[n][i].api=a[n][i].api||function(){var a=[].slice.call(arguments,0);"string"==typeof a[0]&&window[dataLayerName].push({event:n+"."+i+":"+a[0],parameters:[].slice.call(arguments,1)})}}(i[c])}(window,"ppms",["tm","cm"]);
})(window, document, 'dataLayer', '${containerId}')`

  const head = document.getElementsByTagName('body')[0]
  head.appendChild(s)
}

This is the leak found with Memlab :

--Similar leaks in this run: 4189--
--Retained size of leaked objects: 1.2MB--
[<synthetic>] (synthetic) @1 [81.6MB]
  --3 (shortcut)--->  [Window / http://www.stock-pro-local.fr:3000] (object) @6271 [55.3KB]
  --sevenTag (property)--->  [Object] (object) @554405 [6KB]
  --debugger (property)--->  [Object] (object) @733763 [484 bytes]
  --stack (property)--->  [Array] (object) @856291 [359.5KB]
  --30 (element)--->  [Object] (object) @2904283 [4.5KB]
  --dataLayerElement (property)--->  [Object] (object) @2567301 [52 bytes]
  --element (property)--->  [Detached HTMLSpanElement] (native) @1713159 [348 bytes]
  --7 (element)--->  [Detached HTMLButtonElement] (native) @1713183 [448 bytes]
  --8 (element)--->  [Detached HTMLDivElement] (native) @1712889 [144 bytes]
  --7 (element)--->  [Detached HTMLDivElement] (native) @1713591 [144 bytes]
  --7 (element)--->  [Detached HTMLDivElement] (native) @1713685 [124 bytes]
  --5 (element)--->  [Detached HTMLDivElement] (native) @1714657 [144 bytes]
  --7 (element)--->  [Detached HTMLDivElement] (native) @1714653 [144 bytes]
  --8 (element)--->  [Detached Text] (native) @1713883 [108 bytes]
  --5 (element)--->  [Detached HTMLDivElement] (native) @1713881 [189.8KB]
  --6 (element)--->  [Detached HTMLDivElement] (native) @1713879 [189.6KB]
  --5 (element)--->  [Detached HTMLDivElement] (native) @1714101 [189.4KB]
  --5 (element)--->  [Detached HTMLDivElement] (native) @1714085 [189.2KB]
  --6 (element)--->  [Detached HTMLDivElement] (native) @1714083 [1.4KB]
  --8 (element)--->  [Detached Text] (native) @1714059 [108 bytes]
  --5 (element)--->  [Detached HTMLDivElement] (native) @1714057 [187.3KB]
  --5 (element)--->  [Detached HTMLDivElement] (native) @1714055 [344 bytes]
  --9 (element)--->  [Detached Text] (native) @1714049 [108 bytes]
  --5 (element)--->  [Detached HTMLDivElement] (native) @1714047 [186.2KB]
  --5 (element)--->  [Detached HTMLAnchorElement] (native) @1714019 [5.1KB]
  --10 (element)--->  [Detached HTMLAnchorElement] (native) @1713721 [5.1KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1713081 [5.2KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1712631 [5KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1712415 [5.2KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1712193 [5.2KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1711875 [5.2KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1711607 [5.2KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1711329 [5.2KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1711769 [5.2KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1712221 [5KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1712615 [5KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1713663 [5.2KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1714147 [5.1KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1714523 [5KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1714877 [5KB]
  --11 (element)--->  [Detached HTMLAnchorElement] (native) @1710845 [5KB]
  --7 (element)--->  [Detached HTMLDivElement] (native) @1710565 [4.8KB]
  --5 (element)--->  [Detached HTMLDivElement] (native) @1710563 [3.4KB]
  --5 (element)--->  [Detached HTMLDivElement] (native) @1710561 [980 bytes]
  --5 (element)--->  [Detached HTMLDivElement] (native) @1710545 [312 bytes]
  --8 (element)--->  [Detached InternalNode] (native) @89478 [128 bytes]
  --1 (element)--->  [Detached InternalNode] (native) @102682 [128 bytes]
  --2 (element)--->  [Detached ElementIntersectionObserverData] (native) @102686 [72 bytes]

how could you help me with this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant