Clear memory of parent class instance created by calling super/extends

Dolly

Good day,

I am facing some memory allocation problem where I have a class Car extending another class CarParent and then creating the instance of Car class somewhere else in the application. But on setting null to car instance is not deleting the instance of parent created because of super keyword.

Class car:

export class Car extends CarParent {
    constructor() {
        super();
    }

    public go(msg: string): string {
        console.log(msg);
        return msg;
    }
}

Class CarParent

class CarParent {
    constructor() {
    }

    getParts() {
        console.log("you will get parts")
    }
}

Inside application:

import { Car } from './car';

class Company {
    config;
    car;
    constructor(config) {
        this.config = config;
        this.car = new Car();
    }

    delete() {
        this.car = null;
        this.config = null;
    }
}

function Config(config) {
    const company: Company = new Company(config);
    return company;
}

export default Config;

On Index.html

<script>
                var config = { place: "france" };
                var box = new Renderer();
                box.delete();
                box = null;
</script>

Tried to debug from heap allocation:

First both Car and CarParent instance created(Screenshot): enter image description here

After writing box.delete() and box = null and taking snapshot again i can see car instance is deleted: enter image description here

But CarParent instance does not delete: enter image description here

I am confused. Why this is happening? Is it correct, whatever happening or how can i delete memory occupied by CarParent.

Please help!

Bergi

the instance of parent created because of super keyword

No, super() does not create a separate instance.

I am confused. Why this is happening?

The CarParent "instance" you are seeing in the heap snapshot is Car.prototype - it's an object inheriting from CarParent.prototype. You can see how it holds the .go method and Car as its .constructor.

You do not want to delete it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to tell if an instance of a parent class was created from an instance of a particular child

From Dev

Destructing Matlab Singleton class instance without calling `clear all`

From Dev

Destructing Matlab Singleton class instance without calling `clear all`

From Dev

New instance of class created or just space in memory allocated?

From Dev

Calling `super()` in parent class

From Dev

How do I get the calling instance of an object from inside a method in its parent class?

From Dev

Java class instance recursive calling

From Dev

Calling parent method from a class

From Dev

Calling child functions with parent class

From Dev

How to get parent class instance?

From Dev

Target last instance of class in parent

From Dev

How to get parent class instance?

From Dev

Calling an instance of same class inside class

From Dev

Get the calling parent class in a static child class

From Dev

Calling method of the base class (not the immediate parent class)

From Dev

Check if parent class is instance of child class

From Dev

Memory allocation is based on reference class or instance class?

From Dev

Memory allocation is based on reference class or instance class?

From Dev

How to clear DOM elements created with jQuery from memory?

From Dev

Memory Leaks without calling clear() on C++ STL container objects

From Dev

Calling clear() on a vector of shared_ptr. Will memory be freed?

From Dev

How to create an instance of the class is created at run time

From Dev

Is there a way to find out which class instance created 'this'

From Dev

Are Cglib Method Interceptors created per class instance?

From Dev

Calling class/static method and assigning to an instance variable

From Dev

Calling instance method from another class ruby

From Dev

Ruby: trouble calling class instance from method

From Dev

Calling an instance method in designated initializer of a Swift class

From Dev

Calling function error: explicit instance of the class

Related Related

  1. 1

    How to tell if an instance of a parent class was created from an instance of a particular child

  2. 2

    Destructing Matlab Singleton class instance without calling `clear all`

  3. 3

    Destructing Matlab Singleton class instance without calling `clear all`

  4. 4

    New instance of class created or just space in memory allocated?

  5. 5

    Calling `super()` in parent class

  6. 6

    How do I get the calling instance of an object from inside a method in its parent class?

  7. 7

    Java class instance recursive calling

  8. 8

    Calling parent method from a class

  9. 9

    Calling child functions with parent class

  10. 10

    How to get parent class instance?

  11. 11

    Target last instance of class in parent

  12. 12

    How to get parent class instance?

  13. 13

    Calling an instance of same class inside class

  14. 14

    Get the calling parent class in a static child class

  15. 15

    Calling method of the base class (not the immediate parent class)

  16. 16

    Check if parent class is instance of child class

  17. 17

    Memory allocation is based on reference class or instance class?

  18. 18

    Memory allocation is based on reference class or instance class?

  19. 19

    How to clear DOM elements created with jQuery from memory?

  20. 20

    Memory Leaks without calling clear() on C++ STL container objects

  21. 21

    Calling clear() on a vector of shared_ptr. Will memory be freed?

  22. 22

    How to create an instance of the class is created at run time

  23. 23

    Is there a way to find out which class instance created 'this'

  24. 24

    Are Cglib Method Interceptors created per class instance?

  25. 25

    Calling class/static method and assigning to an instance variable

  26. 26

    Calling instance method from another class ruby

  27. 27

    Ruby: trouble calling class instance from method

  28. 28

    Calling an instance method in designated initializer of a Swift class

  29. 29

    Calling function error: explicit instance of the class

HotTag

Archive