DEV Community

StijnDesender
StijnDesender

Posted on

[Vue/Typescript] Memory leak when changing a value that indicates an index in a computed property

Hi,

I am having issues with a computed property

correctAnswersForCurrentStage(): object {return 
    return this.correctAnswers[this.currentLevel] ?? {};
},
Enter fullscreen mode Exit fullscreen mode

Some context:
this.correctAnswers is an object where the properties are the levels and the values are object for each gate:

this.correctAnswers = {
     "1": {
        "1": 15,
        "2": 25,
        "3": 35,
        "4": 45
    },
    "2": {
        "1": 15,
        "2": 25,
        "3": 35,
        "4": 45
    },
}
Enter fullscreen mode Exit fullscreen mode

so when a level is finished, i increase the level like

this.currentLevel++
Enter fullscreen mode Exit fullscreen mode

and after this everything blocks. I don't know if it's Vue or TypeScript that gives this problem. Or maybe the combination of both?
Anyone an idea why this happens?

Top comments (1)

Collapse
 
stijndesender profile image
StijnDesender

Fixed it. It had nothing to do with above stuff. i oversaw some logic in generating the random wrong answers scenario: Min was set to 5, max to 10. so it had 5 numbers to choose from. level too had 6 and 9 for correct answers. so it only had 3 unused more options left. and i asked it to give me 4 that are not already used