Closed
Description
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
Labels
No labels