I'm trying to figure out how to fix my access violation when I leave a method. I changed from using unique ptr to shared ptr so maybe it's a subtlety of shared\_ptrs. I'm having trouble finding info on shared\_ptrs online. I also used to have the commented out line below and had to change it to use my new class instead of using the vector of objects of unique ptrs. It doesn't have the access violation when I uncomment the curly brackets.

The method looks like this:

```
int ExecuteIt(String& sFileName, String& sInput, String& sOutput)
{
    // make sure we have valid data
    if (sFileName.isEmpty() || sInput.isEmpty() || sOutput.isEmpty())
    {
        return -1;
    }

    int iResult = -1; // error

    CreateDocW(sOutput, sFileName, pWriter, pDeleteWriter);

    CreateDocR(sInput, sFileName, pReader, pDeleteReader);

    //{

    shared_ptr<IFJ> m_spIFJTemp = pReader->vMethodImpl1();

    if (m_spIFJTemp && !m_spIFJTemp->isVectorIfdEmpty())
    {
        //auto RootContainerIter = vDocRootContainers->begin();
        pWriter->vMethodImpl2(m_spIFJTemp);
        //pWriter->vMethodImpl2(move(*RootContainerIter));

        iResult = 0; // Success
    }
    //}
    Cleanup(); //before step into cleanup m_spIFJTemp has shared_ptr {m_spVectorIFD={ size=1 } } [2 strong refs] [make_shared]  std::shared_ptr<IFJ>
        //after cleanup m_spIFJTemp has shared_ptr {m_spVectorIFD={ size=??? } } [1 strong ref] [{_Uses=1 _Weaks=1 }]   std::shared_ptr<IFJ>

    return iResult;  //when I uncomment the extra curly brackets it steps 
                         //into a memory _Decref() and has access violation
                         //reading location in _Destroy() 
}

```

Cleanup is like this:

```
void Cleanup()
{
    // Cleanup the reader
    if (pDeleteReader != nullptr)
    {
        pDeleteReader();
        pDeleteReader = nullptr;
    }

    // unload the reader
    if (pReaderLibHandle != nullptr)
    {
        dlclose(pReaderLibHandle);
        pReaderLibHandle = nullptr;
    }

    // Cleanup the writer
    if (pDeleteWriter != nullptr)
    {
        pDeleteWriter();
        pDeleteWriter = nullptr;
    }

    // unload the writer
    if (pWriterLibHandle != nullptr)
    {
        dlclose(pWriterLibHandle);
        pWriterLibHandle = nullptr;
    }
}

```

I found this info [accessviolation](https://stackoverflow.com/questions/6182443/unhandled-exception-at-0x00051526-access-violation-reading-location-0x00000004) online but I checked and I don't create any shared\_ptr with new and I've been trying to look at it in the debugger and I'm not sure about the strong ref's to the shared\_ptr. 

Please let me know if you have any input as to what could be causing this. I would appreciate any helpful response.