# ScopedPointer and Introjucer

**URL:** <https://forum.juce.com/t/scopedpointer-and-introjucer/10712>\
**Category:** General JUCE discussion\
**Created:** [July 1, 2013, 6:16pm UTC](https://forum.juce.com/t/scopedpointer-and-introjucer/10712 "2013-07-01T18:16:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rebbur](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rebbur](https://forum.juce.com/u/rebbur)\
**Post date:** [July 1, 2013, 6:16pm UTC](https://forum.juce.com/t/scopedpointer-and-introjucer/10712/1 "2013-07-01T18:16:32Z")

</div>

Why does the Introjucer do this:

```auto
//header
ScopedPointer<ToggleButton> toggleButton;
//

//==============================================================================
MyComponent::MyComponent ()
{
    addAndMakeVisible (toggleButton = new ToggleButton ("new toggle button"));
    toggleButton->addListener (this);

    //[UserPreSize]
    //[/UserPreSize]

    setSize (600, 400);

    //[Constructor] You can add your own custom stuff here..
    //[/Constructor]
}

MyComponent::~MyComponent()
{
    //[Destructor_pre]. You can add your own custom destruction code here..
    //[/Destructor_pre]

    toggleButton = nullptr;

    //[Destructor]. You can add your own custom destruction code here..
    //[/Destructor]
}
```

Because the toggleButton is a scopedPointer, why would we need to put ‘toggleButton = nullptr’, it will go out of scoped and get deleted.  
Just wondering as i’m using the Introjucer now a lot while converting our Juce 1.50 based project, just wondering if i’m not making wrong assumptions.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 1, 2013, 6:55pm UTC](https://forum.juce.com/t/scopedpointer-and-introjucer/10712/2 "2013-07-01T18:55:30Z")

</div>

Yes - in this case (and most cases) it’d work just the same without needing to clear the pointer, of course.

The reason I added the explicit “= nullptr” statements is that the old code-generator used to call “deleteAndZero” there, so I needed to provide the same behaviour in case people had put code in their [Destructor] user-code section following the destruction of the child comps which would fail if the child comps still existed at that point.

---

<div class="post-metadata">

**Author:** ![rebbur](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rebbur](https://forum.juce.com/u/rebbur)\
**Post date:** [July 2, 2013, 7:03am UTC](https://forum.juce.com/t/scopedpointer-and-introjucer/10712/3 "2013-07-02T07:03:09Z")

</div>

ok, thanks Jules. Already thought it would be something along those lines. Just checking if i wasn’t missing something.
