CefRefPtr and automatic link counting

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CefRefPtr and automatic link counting

Postby Staxcelrom » Sat May 28, 2022 11:09 am

Hello,

I really don't like smart pointers, automatic reference counting and everything related to it.

Please explain with this example, is it possible to do so?


Standard example:

Code: Select all
CefRefPtr<CefStringVisitor>my_CefStringVisitor_get_html_ptr;


   void OnLoadEnd(CefRefPtr< CefBrowser >browser, CefRefPtr<CefFrame>frame, int httpStatusCode) override
   {

      CefRefPtr<CefFrame> my_CefFrame = (*browser).GetMainFrame(); 

                my_CefStringVisitor_get_html_ptr = new my_get_html();

          (*my_CefFrame).GetSource(my_CefStringVisitor_get_html_ptr);

        }

class my_get_html : public CefStringVisitor
   {
   public:

      void Visit(const CefString& my_cstring) override
      {
         //std::cout << "Visit_done" << std::endl;
      }

   private:

      IMPLEMENT_REFCOUNTING(my_get_html);
   };




Can it be done like this? :

Code: Select all
std::deque<CefStringVisitor>my_deq_CefStringVisitor_p;


   void OnLoadEnd(CefRefPtr< CefBrowser >browser, CefRefPtr<CefFrame>frame, int httpStatusCode) override
   {

      CefRefPtr<CefFrame> my_CefFrame = (*browser).GetMainFrame(); 

              CefStringVisitor* CefStringVisitor_p = new my_get_html();

              my_deq_CefStringVisitor_p.push_back(CefStringVisitor_p );

          (*my_CefFrame).GetSource(my_deq_CefStringVisitor_p.back());

        }


class my_get_html : public CefStringVisitor
   {
   public:

      void Visit(const CefString& my_cstring) override
      {
         //std::cout << "Visit_done" << std::endl;
      }
   };


void OnBeforeClose(CefRefPtr<CefBrowser>my_CefBrowser_ptr) override
{

for(int i=0; i<my_deq_CefStringVisitor_p.size(); i++)
{
delete my_deq_CefStringVisitor_p[i];
}

}
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: CefRefPtr and automatic link counting

Postby magreenblatt » Sat May 28, 2022 2:13 pm

You need to store CefRefPtr<CefStringVisitor> in the container.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 42 guests