as.a.bell
as.a.bell

Reputation: 21

WebRTC capture NSCursor image cause memory leak

I face the problem, when I use the module desktop capture of the WebRTC to capture screen and mouse. NSCursor* nscursor = [NSCursor currentSystemCursor]; I found this line cause memory leak. That's a loop function in a thread, about 200ms to capture once.I don't know how to release the memory.

void MouseCursorMonitorMac::CaptureImage(float scale) {  
   NSCursor* nscursor = [NSCursor currentSystemCursor];

   if (nscursor == nil) return;

   NSImage* nsimage = [nscursor image];

   if (nsimage == nil || !nsimage.isValid) {
     return;
   }
   NSSize nssize = [nsimage size];  // DIP size

   // No need to caputre cursor image if it's unchanged since last capture.
   if ([[nsimage TIFFRepresentation] isEqual:[last_cursor_ TIFFRepresentation]]) {
      return;
   }
   last_cursor_ = nsimage;

   /*
    others
   /*
}

The fallow picture, I only remove all whithout NSCursor* nscursor = [NSCursor currentSystemCursor];

memory leak example

Upvotes: 2

Views: 232

Answers (1)

user2311560
user2311560

Reputation: 104

I had similar issue when I had C++ project and it including Objective-C code. To resolve issue I needed add @autoreleasepool

Upvotes: 2

Related Questions