[Live-devel] mem leak when BasicTaskScheduler destructed
Mr. Xiao
34973832 at qq.com
Thu Apr 28 04:49:22 PDT 2011
hello, please note the followed code:
////////// BasicTaskScheduler //////////
BasicTaskScheduler* BasicTaskScheduler::createNew() {
return new BasicTaskScheduler();
}
#define MAX_SCHEDULER_GRANULARITY 10000 // 10 microseconds: We will return to the event loop at least this often
static void schedulerTickTask(void* clientData) {
((BasicTaskScheduler*)clientData)->scheduleDelayedTask(MAX_SCHEDULER_GRANULARITY, schedulerTickTask, clientData);
}
BasicTaskScheduler::BasicTaskScheduler()
: fMaxNumSockets(0) {
FD_ZERO(&fReadSet);
FD_ZERO(&fWriteSet);
FD_ZERO(&fExceptionSet);
schedulerTickTask(this); // ensures that we handle events frequently
}
BasicTaskScheduler::~BasicTaskScheduler() {
}
this code scheduled a task "schedulerTickTask" when construction, but not unscheduler it.
so, when the BasicTaskScheduler object destruct, it will be mem leak.
class BasicTaskScheduler: public BasicTaskScheduler0 {
public:
static BasicTaskScheduler* createNew();
virtual ~BasicTaskScheduler();
public:
void schedulerTickTask();
protected:
BasicTaskScheduler();
// called only by "createNew()"
protected:
// Redefined virtual functions:
virtual void SingleStep(unsigned maxDelayTime);
virtual void setBackgroundHandling(int socketNum, int conditionSet, BackgroundHandlerProc* handlerProc, void* clientData);
virtual void moveSocketHandling(int oldSocketNum, int newSocketNum);
protected:
// To implement background operations:
int fMaxNumSockets;
fd_set fReadSet;
fd_set fWriteSet;
fd_set fExceptionSet;
TaskToken fTickTask; // !!! THIS ONE !!!
};
////////// BasicTaskScheduler //////////
BasicTaskScheduler* BasicTaskScheduler::createNew() {
return new BasicTaskScheduler();
}
#define MAX_SCHEDULER_GRANULARITY 10000 // 10 microseconds: We will return to the event loop at least this often
static void schedulerTickTask(void* clientData) {
((BasicTaskScheduler*)clientData)->schedulerTickTask();
}
void BasicTaskScheduler::schedulerTickTask()
{
fTickTask = scheduleDelayedTask(MAX_SCHEDULER_GRANULARITY, ::schedulerTickTask, this);
}
BasicTaskScheduler::BasicTaskScheduler()
: fMaxNumSockets(0) {
FD_ZERO(&fReadSet);
FD_ZERO(&fWriteSet);
FD_ZERO(&fExceptionSet);
schedulerTickTask(); // ensures that we handle events frequently
}
BasicTaskScheduler::~BasicTaskScheduler() {
unscheduleDelayedTask(fTickTask); fTickTask = NULL;
}
/////
thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20110428/be6dc341/attachment-0001.html>
More information about the live-devel
mailing list