Skip to content

Charts are never destroyed leading to a memory leak #25

Closed
@twickstrom

Description

@twickstrom

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions