ofFbo deallocate?

Hi,

I am using an ofFbo inside a class which I need to create and delete objects from. My problem is that calling myFbo.allocate() uses a bit of memory, but I cannot find a way of releasing that memory once I’ve finished with the FBO. Can anyone point me in the right direction?

Thanks.

You could store them in a vector and once you remove them they would be erased

You could also use a pointer

However allocating them up front is nice as reallocating will slow you down a bit

Thanks for the reply.

Storing the fbo in a vector still doesn’t seem to release the memory once the vector is cleared. Maybe I misunderstood but this is what I did to test that:

  
void testApp::keyReleased(int key){  
  
    myFbos.clear();  
  
    ofFbo fbo;  
    fbo.allocate(500,500);  
    fbo.begin();  
    ofClear(255,255,255,255);  
    fbo.end();  
  
    myFbos.push_back(fbo);  
}  

Allocating them up front might work but it means that I cannot delete the object which holds the fbo, so I have to reuse them without reallocating them. I would rather find a way of being able to create and delete the object at will as each fbo might need to be a different size.

Is there no way to simply release the memory that the fbo has taken up by allocating it?

Thanks again!

there is a fbo.destroy() but destroy() is called by the destructor so I am not sure why that wouldn’t fire with myFbos.clear();

It looks like destroy() is being called, it’s just not releasing the memory…

Correct me, if I am wrong, but doing anything different from changing some variables state inside all “events” called functions, is not a good idea, because they are not executed on the main thread. May be that’s your problem.

Kamen

I’m wondering if there’s a way to deallocate an fbo now, as I’m running into the same problem that I need to constantly reallocate an fbo instance in order to change it’s size. I’m using it as an offscreen buffer, and throughout runtime images of different sizes need to be rendered onto it.

I’m having the same problems - using an fbo in a class to export an image when the class is created, but each time a new object is created from the class the memory creeps up and up to very high levels making the app slow down. If I remove the fbo stuff it’s all fine. I’ve tried putting the fbo in a vector and clearing it but seems to have no effect.

Is there any way to deallocate an fbo after use?

Have the same problem. I tested the problem with following code. Destroy is certainly called but Xcode tells me allocate is constantly eating memory.

void ofApp::update(){
  for (int i=0;i<100;i++){
    ofFbo dummy;
    dummy.allocate(200, 200, GL_RGBA);
    dummy.begin();
    ofClear(255,255,255, 0);
    ofSetHexColor(0x000000);
    ofRect(0,0,200,200);
    dummy.end();
}

Seems this call is the source of problem.

Hi. I can see this thread is very old, but it might be worth resurrecting it.

I have seen this same issue.
I have a class that might discard an fbo once it is done using it. But the memory never gets deallocated. Over time, the memory piles up.

Has anyone found a proper way to free the memory allocated with ofFbo.allocate?

Thanks.

1 Like

Hi all,

I am still debugging to be sure, but it seems I have the same problem. Memory building up after some time with re-allocated fbos. Memory usage actually keeps on building until the computer gets unresponsive.
Has anyone found a solution or workaround?

thanks & have a great day!
oe

We should check and fix this ( if its still an issue ) but a temp solution for now would be to use a shared_ptr. cc-ing @dimitre

eg:

shared_ptr<ofFbo> myFbo; //in your header / class definition 

//then before you call allocate 
myFbo = make_shared<ofFbo>(); 
myFbo->allocate(width, height, GL_RGB); 

//if you need to manually clear it or delete it
//you will need to do make_shared again before using it 
//it will also free up the resources if the class that is holding it is deleted 
myFbo.reset(); 

//also note that you will use myFbo like a pointer so: 
myFbo.draw(0,0); 
//becomes 
myFbo->draw(0,0); 

//you can also check if its allocated with if 
if( myFbo ){
  myFbo->draw(0,0);
}


2 Likes

Do you have a minimum code example to reproduce the issue? Thanks

1 Like

I’ve tried to replicate this error in the past (and again just now) on macOS and wasn’t able to see it with the loop above (posted by Deqing_Sun in 2015). A simple example would be super helpful, and also how long it takes to observe the leak, platform details, etc.

1 Like

I also just tried on OSX with the nightly build for about 15 minutes, but wasn’t able to reproduce any issue.
in update:

for (int i=0;i<100;i++){
	ofFbo dummy;
	dummy.allocate(200, 200, GL_RGBA);
	dummy.begin();
	ofClear(255,255,255, 0);
	ofSetHexColor(0x000000);
	ofDrawRectangle(0,0,200,200);
	dummy.end();
}
1 Like

Hi all,

actually I am failing in providing a minimum code example. The more I try, the more it seems my problem is somewhere else. I am very sorry for the false alarm.
But thanks for trying to help, I really appreciate!

have a great day!
oe

3 Likes

Let us know if you think the memory issue is in another part of OF.
I’ve seen issues like yours in the past related to ofVideoPlayer for example.