COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 12-24-2016, 06:30 AM   #1
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default Release memory consumed by redraw

I find a problem: when the graphic redraw (called by SetDirty(), IsDirty() and Redraw()) the plugin take a few megabytes from memory and never release them. If the user change too much knobs will consume lot of memory, this is real problem.

Also graphics with dynamic components need continuous redraw which take a lot of memory.

How to release memory after redraw ?
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Old 12-24-2016, 09:00 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Do you have some custom control class you've written that leaks memory when it draws itself?

There's not much more advice to give than to recommend not using raw pointers and manual new/delete. Prefer value based objects first but if not possible, then use smart pointers.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 12-24-2016, 09:05 AM   #3
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by SaschArt View Post
If the user change too much knobs will consume lot of memory, this is real problem.
This may also be because of the host application storing undo states. Is your plugin's state data very large?
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 12-26-2016, 04:45 AM   #4
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default

Sure have custom control build by me to draw graph with bool IsDirty() { return true;}

Problem is to intersect checking.

Return intersect and redraw even if not really intersect.
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Old 12-26-2016, 07:23 AM   #5
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by SaschArt View Post
Sure have custom control build by me to draw graph with bool IsDirty() { return true;}

Problem is to intersect checking.

Return intersect and redraw even if not really intersect.
What does this have to do with memory use? Why is your custom control using and apparently leaking memory when it draws itself?
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 12-26-2016, 09:09 AM   #6
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default

Using CropBitmap() again and again. Can I cache cropped bitmap in the next call load from cache ?
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Old 12-27-2016, 01:42 AM   #7
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default

Any solution to cache cropped bitmap in a custom control to prevent using CropBitmap() to each refresh ?
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Old 12-30-2016, 02:03 AM   #8
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default

I find a solution to store CropBitmap() result in cache and problem solved. I define cacheBitmap type of IBitmap var in IControl then use this code in my custom control

Code:
if (cacheBitmap.W==0)
  cacheBitmap=pGraphics->CropBitmap(....
simple and working
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Old 12-30-2016, 08:34 AM   #9
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by SaschArt View Post
I find a solution to store CropBitmap() result in cache and problem solved. I define cacheBitmap type of IBitmap var in IControl then use this code in my custom control

Code:
if (cacheBitmap.W==0)
  cacheBitmap=pGraphics->CropBitmap(....
simple and working
CropBitmap seems to be adding the cropped bitmap into a cache of its own by calling RetainBitmap...That seems to be working weird, I suspect there's actually a memory leak/overuse going on there.

The cropped bitmaps are added to the IGraphics internal bitmap cache with an ID of -1 and there appears to be no check if a bitmap with that ID is already there. Effectively, it appears calling CropBitmap just keeps on adding bitmaps into the IGraphics cache, with no way to control it. Maybe someone who knows IPlug/IGraphics better can say if I've understood the code correctly? (I don't have an IPlug project at hand here, so I just have to imagine how the code works by reading it.)
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 12-31-2016, 02:30 AM   #10
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Yeah... I guess copped bitmaps should get a unique ID, just like normal bitmaps, so they can be cached properly between instances. It should probably assert that the dimensions of the cropped bitmap match that of the bitmap in the cache.
Tale is offline   Reply With Quote
Old 05-26-2023, 01:42 PM   #11
FelixMagi
Human being with feelings
 
FelixMagi's Avatar
 
Join Date: Mar 2016
Posts: 82
Default

CropBitmap has another problem, it's a dynamically member assigned there: LICE_MemBitmap* pDest = new LICE_MemBitmap(destW, destH); and never deleted
FelixMagi is offline   Reply With Quote
Old 05-27-2023, 01:17 AM   #12
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

I think pDest is added to the static (global) bitmap cache using RetainBitmap(), and so it's deleted by ~BitmapStorage().
Tale is offline   Reply With Quote
Old 05-27-2023, 07:53 AM   #13
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default

The problem with CropBitmap is that it does not allocate the unique ID, allocates -1 to all, must be assigned an unique ID and then loaded after the ID. Also the ID must be saved in the IBitmap structure. That's how it loads:

Code:
IBitmap IGraphics::LoadCropBmp(int ID) {
  LICE_IBitmap* lb = s_bitmapCache.Find(ID);
  return IBitmap(lb, lb->getWidth(), lb->getHeight());
}
The same problem is with ScaleBitmap()
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:51 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.