Questions tagged [destroy]

In object-oriented languages, objects need to be destroyed after their creation to free memory. Destruction can however have a broader meaning. Sometimes, destruction means that resources must be freed or that files must be deleted.

In object-oriented languages, objects need to be destroyed after their creation to free memory. This is not necessarily something that a programmer needs to explicitly instruct. Garbage collected languages such as Java or Python take care of object destruction for you. Other languages such as C++ require the programer to destroy objects explicitly.

Destruction can however have a broader meaning. Sometimes, destruction means that resources must be freed or that files must be deleted.

982 questions
21
votes
1 answer

Rails - AciveRecord use :dependent => :destroy on condition

What will be the best/DRY way to destroy all the dependents of an object based on a condition. ? Ex: class Worker < ActiveRecord::Base has_many :jobs , :dependent => :destroy has_many :coworkers , :dependent => :destroy has_many…
VelLes
  • 1,032
  • 1
  • 10
  • 19
21
votes
5 answers

Backbone JS: how to disable sync for delete?

I am dealing with a threaded comments collection, and when I delete a comment that has children, I do model.destroy() for this comment, and on the server side all its branches get deleted. I wrote a function that once a node is deleted from the…
mvbl fst
  • 5,213
  • 8
  • 42
  • 59
20
votes
5 answers

The right way to kill a process in Java

What's the best way to kill a process in Java ? Get the PID and then killing it with Runtime.exec() ? Use destroyForcibly() ? What's the difference between these two methods, and is there any others solutions ?
Kariamoss
  • 542
  • 1
  • 9
  • 29
20
votes
2 answers

Ruby on Rails - Association gets deleted before "before_destroy"

I have an object A that has_many B's (simple association): has_many :book_accounts, { dependent: :destroy } I was working on a before_destroy callback. I want to check and make sure that there are no C's (which belongs_to B) and D's (which…
Isaac
  • 2,246
  • 5
  • 21
  • 34
20
votes
2 answers

How to effectively destroy 'session' in Java Servlet?

The Servlet I'm working has a variable session. I've tried session.invalidate();, this seem to have destroyed session but when I do a redirect like so response.sendRedirect("restanes.jsp");, it gives me HTTP Status 500 error with this…
Sushan Ghimire
  • 7,307
  • 16
  • 38
  • 65
19
votes
8 answers

Calling servlet's destroy method

As per the link http://www.xyzws.com/Servletfaq/when-is-destroy-of-servlets-called/20, one of the reason of calling destroy method is when the servlet hasn't got a request in a long time. I was thinking there could be some pages that don't get…
Anand
  • 20,708
  • 48
  • 131
  • 198
18
votes
5 answers

Can an object destroy itself?

I have an object which needs to destroy itself. Can it be done? Is the example wrong? void Pawn::specialMoves(Coordinate const& from, Coordinate const& to, int passant) { /*...*/ m_board->replace(to, new Queen(m_colour));//replace pawn by…
danjjl
  • 432
  • 1
  • 5
  • 16
18
votes
5 answers

What is the correct way to dynamically create/release runtime forms?

I always try to create my Applications with memory usage in mind, if you dont need it then don't create it is the way I look at it. Anyway, take the following as an example: Form2:= TForm2.Create(nil); try Form2.ShowModal; finally …
user741875
18
votes
1 answer

If a function returns an UnsafeMutablePointer is it our responsibility to destroy and dealloc?

For example if I were to write this code: var t = time_t() time(&t) let x = localtime(&t) // returns UnsafeMutablePointer println("\(x.memory.tm_hour): \(x.memory.tm_min): \(x.memory.tm_sec)") ...would it also be necessary to also do…
sketchyTech
  • 5,746
  • 1
  • 33
  • 56
18
votes
8 answers

Thread-launched running processes won't destroy (Java)

Starting multiple threads and having each exec() then destroy() a running java process result in some of the process not being destroyed and still running after program exit. Here is some code that reproduce the issue. I noticed the more threads you…
Bastien
  • 658
  • 1
  • 9
  • 24
17
votes
5 answers

Rails - How To Destroy Users Created Under Devise?

For my application, I have user accounts that people can sign up. I use the devise gem for the setup. I also have a users page that lists out all the users registered to the site along with a destroy link. I want my administrator to be able to…
spl
  • 609
  • 2
  • 9
  • 20
17
votes
1 answer

How and when is a @ViewScoped bean destroyed in JSF?

The lifecycle of the @RequestScoped and @SessionScopedBean managed beans are managed by the Servlet container itself since they are basically stored as an attribute of HttpRequest and HttpSession respectively. How do JSF manage the lifecycle of the…
Geek
  • 26,489
  • 43
  • 149
  • 227
15
votes
8 answers

Ever need to destroy a singleton instance?

By using a singleton, only one instance of it can be created. Do we ever need to destroy that instance? I have a singleton DBManager, which manages a JDBC connection and query operations. By calling its static newInstance method, I can get the…
chance
  • 6,307
  • 13
  • 46
  • 70
15
votes
1 answer

Overriding devise SessionsController destroy

I'm trying to override the destroy method from Devise's SessionsController, but I have had no success yet. I've already done it for the create method, but I don't know why it's not working for the destroy method. This is my SessionsController:…
DemianArdus
  • 827
  • 8
  • 20
14
votes
2 answers

PHP: Destroy an object from within the object?

Is there a way in PHP to destroy an object from within that same object?
Spot
  • 7,962
  • 9
  • 46
  • 55
1
2
3
65 66