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
2
votes
4 answers

Can I delete a dynamically allocated class using a function within that class?

I'm writing a state manager for a game. I've got most of the logic down for how I want to do this. I want states, which will be classes, to be handled in a stack in the StateManager class. Each state will have pause functions, and the stack will be…
sonicbhoc
  • 434
  • 3
  • 15
1
vote
4 answers

Optimal way to self-delete QObjects

I have two classes Node and NodeContainer: class Node: public QObject { NodeContainer* parent; } class NodeContainer : QObject { bool deleteChild(Node*child) { if(childNodes->remove(child)) { …
Anton
  • 1,181
  • 2
  • 17
  • 27
1
vote
0 answers

Best practises for remotely self-destructing docker containers & volumes?

We have selections of docker containers that run as a client on a host remotely. This then communicates with a single server that has a front-end and is in charge of multiple of these clusters. We'd like to implement the ability to remotely tell a…
1
vote
2 answers

Self-deleting PowerShell script deletes all contents but not the containing/parent folder

I'm trying to have the PowerShell 5.1 script self-delete itself, along with the entire folder contents (including subfolders). I'm using the below code, which works to a point. It does delete all of the folder's contents (including the PowerShell…
howdoicode
  • 779
  • 8
  • 16
1
vote
0 answers

Self-destroying Python script

For no particular reason (mainly just the joy of experimentation), I'm looking for a way to write a python script, that self-destroys after execution. One simple approach would be to determine the file, that is being called from the file itself and…
Dschoni
  • 3,714
  • 6
  • 45
  • 80
1
vote
1 answer

Self Delete Folder with scripts powershell

I have been trying to have powershell or batch scripts delete a folder that contains all my scripts when I am finished. Originally I tried Remove-Item -Path "C:\Tool" -Recurse -Force which worked no problem if run as a script for a location outside…
1
vote
2 answers

c++ returning into method of deleted object

This is a variation on the delete this debate, to do with what happens with intermediate method calls. Basically, if method A calls method B, and method B destroys the object, does anything particular happen inside method A when returning from B?…
Xeren Narcy
  • 875
  • 5
  • 15
1
vote
2 answers

Suicide: Objective-C objects calling their own -dealloc methods on themselves

Is it good practice for an object in Objective-C to commit suicide? That is, for an object to declare [self dealloc] where -dealloc permits an orderly wind down as usual? What are the principal risks? As it happens I have a specific example, a…
Ken
  • 30,811
  • 34
  • 116
  • 155
1
vote
1 answer

Is a member function allowed to explicitly call its class destructor

Does the following code have a defined behavior ? If not, what part of the code is UB and what section(s) of the standard states it is UB ? If this code is UB, is there any [minor] change that can fix it ? If nothing can fix it, what other code…
shrike
  • 4,449
  • 2
  • 22
  • 38
1
vote
2 answers

Self Modification of .exe c file after execution

I have a c code with a character array initialized to "hello world". I would like to know if there is a possibility to re-initialize this character array upon each execution of the code, to some other random string. If not C, may I know if such an…
1
vote
0 answers

Destroying object in member function C++

class Base{ virtual void sth() =0; virtual void destroy_me(){} }; class Derived : public Base{ void sth(){} void destroy_me(){ delete this; } }; Is this safe behavior if I am absolutely sure that Derived was dynamically allocated? I…
niko
  • 1,128
  • 1
  • 11
  • 25
1
vote
3 answers

How are self-destructing type erasure classes like std::function implemented?

I want to understand how the implementation of std::function works. For simplicity, let's consider move-only functions with no arguments. I understand that std::function erases the type of its target through typical type erasure…
Jared Hoberock
  • 11,118
  • 3
  • 40
  • 76
0
votes
1 answer

How can I create an app which deletes itself?

How can i write a function that can remotely self-destruct it, ie delete that application from the phone? Intent intent = new Intent(Intent.ACTION_DELETE); intent.setData(Uri.parse("package:com.example.myapplication")); startActivity(intent); This…
Hayk
  • 1
0
votes
0 answers

Is it possible to self destruct the directory of a batch and all its contents?

I have a batch which copies some files from a directory and then should delete the directory the batch file is in, but it just deletes the contents and not the folder itself. I tried with rmdir and with del. The folder structure is the…
New
  • 1
  • 4
0
votes
0 answers

Can I send disappearing SMS on android device?

Is there anyway send a message which is not saved in the receivers message box and is removed after reading once? I searched on google and find something like self-destructing message. https://www.mashnol.org/self-destructing-text-message-app/ But…