Questions tagged [self-destruction]

Self destruction is a procedure or algorithm that is programmed to destroy the caller object, or the invoker file or pointer.

Self destruction is a procedure or algorithm that is programmed to destroy the caller object, or the invoker file or pointer. Self destruction is often used when an object, a file or a pointer must be used only once - then it triggers the self destruction procedure right after being invoked, referenced or called.

56 questions
7
votes
2 answers

When should a service worker self destruct?

I found this repo describing HOW to destroy a service worker. But I didn't find any resources describing WHEN a worker should destroy/uninstall/unregister itself. When I develop websites, I often use port 8080. I can be working on site X that has a…
7
votes
3 answers

Object-Oriented Suicide or delete this;

The following code compiled with MSVC9.0 runs and outputs Destructor four times, which is logical. #include class SomeClass { public: void CommitSuicide() { delete this; } void Reincarnate() { …
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
7
votes
8 answers

Is it OK to use "delete this" to delete the current object?

I'm writing a linked list and I want a struct's destructor (a Node struct) to simply delete itself, and not have any side effects. I want my list's destructor to iteratively call the Node destructor on itself (storing the next node temporarily),…
jkeys
  • 3,803
  • 11
  • 39
  • 63
6
votes
2 answers

Self-Deleting Script for both Linux Bash and Windows Batch

I have an uninstall script that cleans up an add-on tool used with an application. Versions of the script run on both Windows and Linux. I'd like to be able to delete the uninstall script file and also the directory in which the script runs too (in…
George Hernando
  • 2,550
  • 7
  • 41
  • 61
6
votes
3 answers

How can a object self destruct on an event, in javascript?

I have this function, to create a DIV on-the-fly. But now, I want to destroy this object on onclick event, but I just don't know how. function creatediv(id) { var newdiv = document.createElement('div'); newdiv.setAttribute('id', id); …
RSilva
  • 6,753
  • 11
  • 43
  • 49
3
votes
6 answers

Lack of virtual destructor when doing "delete this"

Section 16.15 of the C++ FAQ Lite discusses delete this and then mentions: Naturally the usual caveats apply in cases where your this pointer is a pointer to a base class when you don't have a virtual destructor. Why is this true? Consider this…
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
3
votes
4 answers

Why does the destructor call itself endlessly (causing a stack overflow)?

I am confused on why the destructor calls itself an endless amount of times, when I try to construct an object say LeakySingleton on the heap through a static function call create_instance() and then try to delete it explicitly afterwards via the…
3
votes
8 answers

How could one design a secure and "self-destructing" email?

As most of you know, email is very insecure. Even with a SSL-secured connection between the client and the server that sends an email, the message itself will be in plaintext while it hops around nodes across the Internet, leaving it vulnerable to…
quantumSoup
  • 27,197
  • 9
  • 43
  • 57
3
votes
7 answers

What will happen if a std::vector element 'commits suicide' (using delete this;)?

Suppose there's a vector of Items vector items; //{item1, item2, item3} Then, in other part of the code, items[1]->suicide(); where the suicide function is: void Item::suicide() { delete this; } What is items vector size and how it's…
rismanrp
  • 87
  • 1
  • 8
2
votes
3 answers

My code crashes on delete this

I get a segmentation fault when attempting to delete this. I know what you think about delete this, but it has been left over by my predecessor. I am aware of some precautions I should take, which have been validated and taken care of. I don't get…
Eric
  • 19,525
  • 19
  • 84
  • 147
2
votes
5 answers

delete this ? what does it do?

Given the following : #include using namespace std; class A { public: void func() {delete this;} A() : x(5) {cout << "ctor A" << endl;} ~A() {cout << "dtor A" << endl;} int x; }; int main() { A a; cout << "The X…
Ron_s
  • 1,429
  • 1
  • 14
  • 24
2
votes
1 answer

How to update a value in destructing and loop

What I try to achieve: I want to update a value in an obj, which is part of the element of array. See the code below will give you better idea. There is an issue that I update the value of object, via reference, instead of making a copy. This causes…
kenpeter
  • 7,404
  • 14
  • 64
  • 95
2
votes
0 answers

Error: Returned values aren't valid, did it run Out of Gas? on selfdestruct()

the code works fine, cause i'm following an online crash course. my problem is when i enter selfdestruct() it says something about an error, that i am unsure of what. please have a look, and see what is the problem. here is the code on where the…
2
votes
2 answers

QObject selfdestruction aware container

Is there a Qt container, that is aware of the destroyed signal of QObject and removes the element if an element was destroyed? I.e. like this: QObject *obj1 = new MyObject(); QObject *obj2 = new MyObject(); QObjectContainer…
ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103
2
votes
1 answer

How can I remove an attribute from an element in angular?

How can I remove an attribute (or at least its value) using Angular? In specific, lets say I have an ng-click event. I want this even to only fire once and I think the easiest way to do this would be to have a 'self-destruct' in the ng-click event.…