Is FreeBrush() necessary to call before LoadBrush()

Find quick help here to get you started with Hollywood
Post Reply
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Is FreeBrush() necessary to call before LoadBrush()

Post by mrupp »

Hi there

In my RapaGUI app I'm having an <image> widget that will always display my brush #1. So I'm loading an image into brush #1 and later overwriting it with another image. Now I'm concerned about memory consumption and garbage collection: is it advisable to always call FreeBrush() first before loading the new brush #1?

Example:

Code: Select all

@BRUSH 1, "images/empty.png"
(...)
LoadBrush(1, "images/brush1.png")
(...)
LoadBrush(1, "images/brush2.png")
(...)
LoadBrush(1, "images/brush3.png")
(...)
Would it be better to do it like this or maybe it doesn't matter because LoadBrush() might already handle this?

Code: Select all

@BRUSH 1, "images/empty.png"
(...)
FreeBrush(1)
LoadBrush(1, "images/brush1.png")
(...)
FreeBrush(1)
LoadBrush(1, "images/brush2.png")
(...)
FreeBrush(1)
LoadBrush(1, "images/brush3.png")
(...)
Cheers, Michael
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: Is FreeBrush() necessary to call before LoadBrush()

Post by lazi »

Suggested read: RapaGUI - Image cache
https://www.hollywood-mal.com/docs/html ... Cache.html
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Re: Is FreeBrush() necessary to call before LoadBrush()

Post by mrupp »

lazi wrote: Sat Aug 28, 2021 11:21 pm Suggested read: RapaGUI - Image cache
https://www.hollywood-mal.com/docs/html ... Cache.html
I know, brushes for the <image> widget aren't cached. That doesn't really answer my question, though, does it?
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Is FreeBrush() necessary to call before LoadBrush()

Post by airsoftsoftwair »

When passing an ID that already exists to LoadBrush(), LoadBrush() will implicitly call FreeBrush() so it won't make a difference to call this manually before LoadBrush(). As Lazi has pointed out, with RapaGUI things might be a little different because of the image cache but as you correctly said, <image> images aren't cached...
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Re: Is FreeBrush() necessary to call before LoadBrush()

Post by mrupp »

airsoftsoftwair wrote: Thu Sep 02, 2021 8:45 pm When passing an ID that already exists to LoadBrush(), LoadBrush() will implicitly call FreeBrush() so it won't make a difference to call this manually before LoadBrush().
That was the information I was looking for. Thanks!
Maybe this could be added to the LoadBrush() / FreeBrush() chapters in the doc.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Is FreeBrush() necessary to call before LoadBrush()

Post by airsoftsoftwair »

mrupp wrote: Fri Sep 03, 2021 1:24 pm Maybe this could be added to the LoadBrush() / FreeBrush() chapters in the doc.
Since this behaviour applies to all of the object creation functions, I've added a note to the Object library overview that explains it. Otherwise it would have to be added to dozens of pages.
Post Reply