Why Doesn't Delete Destroy Anything

Why doesn't delete destroy anything?

It's time to learn what undefined behavior is. :)

In C++, when you do something illegal/nonsensical/bad/etc. the standard often says that "it leads to undefined behavior." This means that from that point forward, the state of your program is completely non-guaranteed, and anything could happen.

At the point where you do your last *(pTest), you get undefined behavior. This is because pTest does not point to a valid object, and dereferencing such a pointer is undefined. So what you're seeing is totally allowed: undefined output.

All you've done is said "I'm finished with this allocation." Once you've said that, you shouldn't (and indeed, cannot) inspect or care about that memory any longer. It doesn't even make conceptual sense to deallocate something then try to use it; you've said you were done!

Your output is somewhat predictable though: likely, your OS simply says "okay, thanks for the memory" and that's it. It has no reason to actually "reset" the memory, or do anything special. That would indeed be a waste of time, when nobody (including your own program) is not using it.

But remember, this output is completely undefined. Don't try to use objects that don't exist. Perhaps a better test would have been:

#include <iostream>

struct foo
{
~foo()
{
std::cout << "foo is gone :(" << std::endl;
}
};

int main(void)
{
foo* f = new foo();
delete f; // you'll see that the object is destroyed.
}

Although it seems you were looking to see what happens with the memory itself. Just remember that it makes no sense to get rid of memory then try to use it, so the answer is: who knows. It's up to your specific platform, which C++ doesn't care about.

c++ destructor doesn't delete the object itself, what does?

See option 3 on my question.

There are no memory leaks, there is never more than one StrPtr object in memory.

Difference between Destroy and Delete

Basically destroy runs any callbacks on the model while delete doesn't.

From the Rails API:

  • ActiveRecord::Persistence.delete

    Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted). Returns the frozen instance.

    The row is simply removed with an SQL DELETE statement on the record's primary key, and no callbacks are executed.

    To enforce the object's before_destroy and after_destroy callbacks or any :dependent association options, use #destroy.

  • ActiveRecord::Persistence.destroy

    Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted).

    There's a series of callbacks associated with destroy. If the before_destroy callback return false the action is cancelled and destroy returns false. See ActiveRecord::Callbacks for further details.

Why doesn't direct path for delete/destroy exist in rails?

In typical link_to links the browser will send HTTP GET requests. When you're destroying a resource the browser should send a HTTP DELETE request. Rails has some javascript that will run on those links and intercept the click to send a HTTP DELETE request for those marked with method: :delete. Also the path for a single resource to be destroyed and shown will be the same.

event_path will return "/event/1" or similar. When sending a HTTP GET request its expected that the show action of your controller will be called. When sending a HTTP DELETE request to the same path its expected that the destroy action will be called.

Delete/Destroy method doesn't work anymore? (Rails)

Actually the problem was probably Firefox. When I clicked on Answer you own question here on Stackoverflow, I had the very same problem: My request, wasn't processed properly. I was sent back to the normal question view, without having the ability to submit my own answer.

So after a restart of Firefox everything worked fine.

(I also reinstalled Ruby and Rails at the same time, so I can't be sure, if it was Firefox for sure).

Delete / Destroy is not working in rails 3 with jQuery

I ran into the same issue Mohit had and also needed to include the 'Unobtrusive JavaScript Library' (or 'ujs') in my JavaScript assets. In my current Rails (v3.2.5), the UJS library will be provided automatically. You can verify this by seeing the following line in your Gemfile:

gem 'jquery-rails'

and the following line in your app/assets/javascripts/application.js file:

//= require jquery_ujs

Since I didn't know any better, I had removed the require jquery_ujs line from my own application.js file, and it took me a while to figure out why my link_to ..., :method => :delete calls weren't working any more!

Once I understood the problem, it was easy to add the above two lines back to their respective files and everything started working as expected again.

Why doesn't deleting a file in TFS and then recreating it wipe out the history?

Deleting the folder in TFS will only actually perform a "soft delete". The branch will still exist complete with all of its history, except it will be hidden. You could show the deleted items in VS follow this tutorial.

If you want to permanently deletes version-controlled files from Team Foundation version control, need to perform a tf destroy command.

tf destroy [/keephistory] <itemspec1>[;<versionspec>][<itemspec2>...<itemspecN>] 
[/stopat:<versionspec>] [/preview] [/startcleanup] [/noprompt] [/silent] [/login:username,[password]] [/collection:TeamProjectCollectionUrl]]

There is not any built-in button or UI designed to quick destroy files in TFS. We suggest you to use some tf command line to achieve this.

Make things complicated is preventing user destroy files/folders accidentally. Since tf destory command permanently deletes files from TFS. Use with great caution. There is no recovery.

Besides, even though you don't have to delete a file/folders before destroying it in TFS. However:

Before you run tf destroy without the /keephistory option, we
recommend that you first delete the files you want to destroy.

After you delete the files you can synchronize the Team Foundation
warehouse. Otherwise, the warehouse will not be synchronized with the
destroyed items.

For more detail information, see Delete Files and Folders from Version Control.



Related Topics



Leave a reply



Submit