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

Charts are never destroyed leading to a memory leak #25

Closed
twickstrom opened this issue Oct 17, 2018 · 1 comment
Closed

Charts are never destroyed leading to a memory leak #25

twickstrom opened this issue Oct 17, 2018 · 1 comment

Comments

@twickstrom
Copy link
Contributor

Charts are never destroyed and leads to a memory leak.

I will submit a pull request to handle this properly, see https://vuejs.org/v2/cookbook/avoiding-memory-leaks.html#Resolving-the-Memory-Leak

Until then, this is a work around (simplified example in a component):

<template>
    <GChart
      v-if="data.length"
      type='PieChart'
      :data='data'
      :options='options'
      @ready="onChartReady"
    />
</template>
<script>
export default {
  data () {
    return {
      chart: null,
      data: [],
      options: {}
    }
  },
  beforeDestroy () {
    if (this.chart) {
      this.chart.clearChart()
    }
  },
  methods: {
    onChartReady (chart, google) {
      this.chart = chart
    }
  }
}
</script>

The important part are adding @ready="onChartReady" to the GChart element and storing a reference to the chart.

Then adding the beforeDestroy method and using googles clearChart() method.

In the pull request I will add this to the vue-google-chart directly as this is where it should be taken care of.

@nobilix
Copy link
Contributor

nobilix commented Oct 18, 2018

thanks, updated: vue-google-charts@0.3.2

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

2 participants