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
278
votes
10 answers

Is "delete this" allowed in C++?

Is it allowed to delete this; if the delete-statement is the last statement that will be executed on that instance of the class? Of course I'm sure that the object represented by the this-pointer is newly-created. I'm thinking about something like…
35
votes
10 answers

Is it safe to `delete this`?

In my initial basic tests it is perfectly safe to do so. However, it has struck me that attempting to manipulate this later in a function that deletes this could be a runtime error. Is this true, and is it normally safe to delete this? or are…
Cristián Romo
  • 9,814
  • 12
  • 50
  • 50
35
votes
6 answers

How to make scripts auto-delete at the end of execution?

Is it possible to make a python script that will delete the .py file at the end of its execution (self-delete) in windows?
Serban Razvan
  • 4,250
  • 3
  • 21
  • 22
32
votes
7 answers

Self deletable application in C# in one executable

Is it possible to make an application in C# that will be able to delete itself in some condition. I need to write an updater for my application but I don't want the executable to be left after the update process. There is an official .Net OneClick…
George
  • 1,466
  • 3
  • 12
  • 30
31
votes
3 answers

"delete this" in constructor

What actually happen when I execute this code? class MyClass { MyClass() { //do something delete this; } }
uray
  • 11,254
  • 13
  • 54
  • 74
29
votes
4 answers

What is the use of "delete this"?

Today, I have seen some legacy code. In the destructor there is a statement like "delete this". I think, this call will be recursive. Why it is working? I made some quick search on Y!, I found that if there is a need to restrict the user to create…
Vinay
  • 4,743
  • 7
  • 33
  • 43
28
votes
4 answers

PHP file that should run once and delete itself. Is it possible?

Is it possible to create a PHP file that runs once with no errors and deletes itself?
Rella
  • 65,003
  • 109
  • 363
  • 636
24
votes
11 answers

Should objects delete themselves in C++?

I've spent the last 4 years in C# so I'm interested in current best practices and common design patterns in C++. Consider the following partial example: class World { public: void Add(Object *object); void Remove(Object *object); void…
Generic Error
  • 4,437
  • 6
  • 28
  • 26
24
votes
11 answers

How can I make my .NET application erase itself?

How can I make my C# app erase itself (self-destruct)? Here's two ways that I think might work: Supply another program that deletes the main program. How is this deleter program deleted then, though? Create a process to CMD that waits a few seconds…
Maxim Zaslavsky
  • 17,787
  • 30
  • 107
  • 173
20
votes
12 answers

Should "delete this" be called from within a member method?

I was just reading this article and wanted SO folks advice: Q: Should delete this; be called from within a member method?
jldupont
  • 93,734
  • 56
  • 203
  • 318
17
votes
4 answers

Delphi: Is it ok for a form to free it self?

I have a form that I use to show some information for some seconds. Is it ok for the form to free itself? Can I start a timer in the constructor, and then call self.free in the timer-event? Or will this potentially lead to trouble?
Vegar
  • 12,828
  • 16
  • 85
  • 151
14
votes
2 answers

Self deleting bash script

How can a bash script execute even after encountering a statement to delete itself? For eg when I ran test.sh script which conains: <--some commands--> rm test.sh <--some more commands--> end The script executes till the end before deleting itself
user1004985
  • 2,573
  • 4
  • 19
  • 16
14
votes
4 answers

Self-destructing application

Along the lines of "This tape will self-destruct in five seconds. Good luck, Jim"... Would it be possible for an application to delete itself (or it's executable wrapper form) once a preset time of use or other condition has been…
James P.
  • 19,313
  • 27
  • 97
  • 155
11
votes
5 answers

Is it possible to write a self-destructive program in C?

Is it possible to write a program in C that upon execution deletes itself (the binary) and then terminates successfully. If so, what's the easiest way of doing this?
Alex Coplan
  • 13,211
  • 19
  • 77
  • 138
8
votes
3 answers

Is it valid to directly call a (virtual) destructor?

In this answer, Ryan directly calls the virtual destructor. I've tested the code in VS2010, and it correctly calls all destructors (tested with logging statements). Is it actually valid to do so? What are the problems, flaws or even the good points…
Xeo
  • 129,499
  • 52
  • 291
  • 397
1
2 3 4