0
class Greeter {
greeting: string;
    constructor(message: string) {
        this.greeting = message;
    }
    greet() {
        return "Hello, " + this.greeting;
    }
}
let greeter = [];
greeter[0] = new Greeter("world");
greeter[1] = new Greeter("world");

I want to delete suppose instance greeter[0]? I have tried by assigning null to greeting[0] as

But it did not affected.

greeter[0] = null;
Roshan
  • 571
  • 4
  • 4
  • Removing all references to an instance will result in it being garbage-collected soon. Reassigning `greeter[0]` will result in the instance at that property becoming unreferenceable, and it will shortly get GC'd. – CertainPerformance Mar 13 '20 at 01:51
  • What do you mean by "*delete*"? Certainly you cannot use that greeter any more after you set the only reference you had to `null`. So how "*it did not affected*"? What is the desired result, and what happened instead? – Bergi Mar 13 '20 at 01:52
  • Your instance is in array. You should use an array function. greeter.splice(0, 1) 0 - start 1 - count – Riku Mar 13 '20 at 01:54
  • Actually i am creating multiple iperf instance . I am creating a new instance while starting server and assigning null to the instance while closing the server. For the first time logs are coming correct. But after stopping the iperf and assigning null to the instance and restarting the server in same instance name ,logs are repeating. – Roshan Mar 13 '20 at 02:08

0 Answers0