google / google-api-javascript-client

Google APIs Client Library for browser JavaScript, aka gapi.
Apache License 2.0
3.22k stars 1.06k forks source link

Memory leak on single page app gapi.client.init #365

Open ditproz opened 6 years ago

ditproz commented 6 years ago

I'm review my code because I have found a memory leak. I'm building a single page app on Angular 2. I'm using the GAPI library @ https://apis.google.com/js/api.js

I have stripped my code back to the bones and have added line by line and function by function to find the issue. Our system uses the GAPI library to login via OAuth and maintain the login status on our app.

It appears as if the gapi.client.init, when included in the code causes a leak in the app. If you review the image, you will see a steady climb of JS objects and at the bottom a repeated call to function Timer Fired which I believe is the setTimeout function. Is this expected behaviour?

stack2

The code in question which seems to cause the behaviour:

    return gapi.client.init (
          return {
               'clientId': this.clientId,
               'scope': this.scope,
               'cookie_policy': 'single_host_origin'
    }
    )

We're able to authenticate with Google via Oauth successfully and the whole app works etc...

Is there a special way to initialise this library on a one page app? What have I done wrong?

I'm testing the app in Chrome Version 62.0.3202.94 (Official Build) (64-bit) Windows 10 64 bit Angular: angular2 2.0.0-beta.21

TMSCH commented 6 years ago

@ditproz thanks for this report. The regular timer is expected, it checks cookies to make sure the user's account is still signed in. However, the constant heap increase seems suspicious. We'll investigate.

ditproz commented 6 years ago

Any ideas why this might occur?

TheHandsomeCoder commented 6 years ago

@ditproz did you find a resolution to this? I seem to be having a similar issue in my own app in React