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

  • Home
  • SEARCH
  • 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 7587785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:45:43+00:00 2026-05-30T19:45:43+00:00

I have a dilemma regarding Smart pointers and memory allocation. In my smart pointer

  • 0

I have a dilemma regarding Smart pointers and memory allocation.

In my smart pointer class I have my own way of allocation memory through a memory module in my engine.

template <class T>
    class Object
    {
    public:
        inline Object()
        {
            Init();

            if (mEngine)
            {
                mObj = (T*) mEngine->GetMemoryManager()->Allocate(sizeof(T));
                mRefCount = 1;
            }
        }

Now when I want to Destroy() my engine, I want all memory to freed as well. This is first of all because I want to cleanup all memory associated with my engine, and also because cleanup of mObj relies upon my memory manager as it may use for example a memory pool to allocate/deallocate memory, and removing that memory manager would lead to unallocatable memory.

So have I shot myself in the foot with smart pointers? Is there a smart way to solve this?

  • 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-05-30T19:45:45+00:00Added an answer on May 30, 2026 at 7:45 pm

    Why so? In fact, this is a common practice to have a smart pointer mixed with a custom memory management. std::shared_ptr (or boost::shared_ptr) supports a custom deleter, reference counted pointer usually have some virtual method that is called to release them etc.

    You cannot, however, destroy the engine while something else is using parts of it, like those referenced objects. For that purpose, people usually make “engine” a reference counted pointer, too. Just be careful about cyclic dependencies.

    … and let the force be with you!

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

Sidebar

Related Questions

I have a dilemma. Suppose I have a template class: template <typename ValueT> class
I have an interesting dilemma. If I define my class as: class Browser {
One common dilemma I have faced throughout programming is regarding declaring variables inside a
I have dilemma about how to organize connection (repository class) to data layer in
I am going through a bit of a design dilemma, I have been targeting
I have an architectural dilemma regarding JUnit Test structure. The flow of my test
I have a dilemma and I'm not sure about the best way to start
We have a dilemma; developing desktop application using Matisse or Jigloo.. Matisse has this
I have a dilemma that I've encountered before. What's the best in terms of
i have little dilemma, i often use data-bound controls such as Gridview in conjunction

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.