Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8002695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:26:20+00:00 2026-06-04T16:26:20+00:00

I have several classes which I connected to AngelScript engine. This engine uses interesting

  • 0

I have several classes which I connected to AngelScript engine. This engine uses interesting way to allocate objects: It allocates needed amount of memory (possibly with malloc()) and when authors propose to use construction like this to create object in this memory:

static void Constructor(ObjectType *thisPointer)
{
    new(thisPointer) ObjectType();
}

and code like this to destroy object:

static void Destructor(ObjectType *thisPointer)
{
     thisPointer->~ObjectType();
}

I have several questions:

  • Is it correct way to use destructor this way? (Eclipse judges this as a bug) As far as I can understand this code should call destructor without deallocating memory (calling free())
  • Is it possible to use delete(thisPointer) (or something like it) instead of this construction and is it will be equivalent? (at least this code gives no errors during compilation and runtime)
  • Is there other ways to call destructor without deallocating memory?

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:26:21+00:00Added an answer on June 4, 2026 at 4:26 pm

    Is it correct way to use destructor this way?

    Yes. You constructed the object in-place using placement-new, and so it must be destroyed with an explicit destructor call (assuming it has a non-trivial destructor).

    Is it possible to use delete(thisPointer) (or something like it) instead of this construction and is it will be equivalent?

    No. delete will attempt to use operator delete() to release the memory to the free store; this is only valid if it was allocated with a normal new expression (or perhaps an explicit use of operator new()).

    Is there other ways to call destructor without deallocating memory?

    Not really. Calling the destructor is certainly the clearest and simplest way to call the destructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a package which contains an interface and several classes,some classes in this
I have several obj-c classes, each of which require a number of constants that
I have a file attachment class (FileAttachment) which is used in several other classes.
This is for a web project so i have several classes that inherit from
I have a question regarding SwingWorker and Java GUI's. I have several classes which
i have several AreaRegistration classes which one each registers own routes and each one
I have a Silverlight application that consists of a MainWindow and several classes which
I have a jar file with several classes which have static main methods. Can
I have several classes which use static variables. I assume that the classes are
I'm implementing several classes which does not have data by itself, just logics. These

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.