Jump to content

How to know if GDI+ is running?


qwert
 Share

Recommended Posts

I've looked back through 5 years of posts and can't find the answer to this:

When exiting a script that uses GDI+, how can I know if GDI+ is actually running and needs to be shut down?

I have a script with several places where GDI+ might be started, but many more possible exits, including the user cancelling out of some of the operations.  I've never tried to track every possible start+exit combination.  Is there a way to determine what, exactly, to do upon exit?

And on a related note:

GDIPlusDispose.au3 is from 2010. Is it still the best answer to all the "dispose" issues?  I haven't noticed its use in examples.

 

Thanks in advance for help with these issues.

Link to comment
Share on other sites

I afraid it's not a easy-to-solve problem.

If you do write script from scratch, you can easily use a counter method. So whenever GDI plus successfully initialized, you increase the counter and when a call to GDI+ finalize successful, you decrease it. That way, when your script ends, you can check if the counter is larger than zero so you must call finalize.

But if you have an old script which not using the method at the beginning, you are in troubles. It's the disadvantages of AutoIt since maintaining an old script is a pain in the ass

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

Thanks for your response.  I guess that explains why I didn't find anything.

Any ideas about the second issue?:

GDIPlusDispose.au3 is from 2010. Is it still the best answer to all the "dispose" issues?  I haven't noticed its use in examples.

 

Link to comment
Share on other sites

OnAutoItExitRegister ( "function" )

OK ... so that should be included following each possible startup points?

Does that mean there might be multiple shutdown calls?  Or does it consolidate into one?

(Thanks for your response.)

 

Link to comment
Share on other sites

Usually you start your script with _GDIPlus_Startup() and when exiting you call _GDIPlus_Shutdown().

All other resources have to be controlled properly to avoid memory leaks! The basic idea of GDIPlusDispose.au3 is good but not every time applicable.

I don't know what happens in the memory when you don't dispose the GDI+ ressources. Probably those areas in the memory will stay write protected and thus not usable.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Usually you start your script with _GDIPlus_Startup() and when exiting you call _GDIPlus_Shutdown().

Yes ... and I've been "going by the book" on all my other scripts that use GDI+.

But this one only uses GDI+ of some of its functions and I didn't want to needlessly start GDI+ if it wasn't going to be used.  Plus, any kind of an abnormal exit could leave an entirely unneeded copy of GDI+ in memory.

I was trying for the proverbial "better way".

Thanks for your response.

 

Link to comment
Share on other sites

GDIPlusDispose.au3 is from 2010. Is it still the best answer to all the "dispose" issues?  I haven't noticed its use in examples.

 

Its depend. That UDF take care all the object you created so they will be disposed when you call its _GUIPlus_Shutdown() function. Like UEZ said, its basic idea is good but IMO, you will pay more than you get. So IMO, you should:

If you need a temporary object, create a local object and dispose right after you finish with it

If you need a object for multiple purpose and want to do with it multiple times, create a global object and then manually dispose it when you script exit. But don't mess with those global things. Try to avoid it.

Edit: According to your description then the UDF may not solve your problems. Its about disposing the created GDI+ obj, not about finalizing the entire GDI+. Maybe the counter will help you (but you need modify your old script terribly)

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

binhnx, thanks for that good explanation.

I'll move ahead, resolved to sort out the details.  But I was hoping there was a blanket solution that I just wasn't aware of.

But don't mess with those global things. Try to avoid it.

That's probably good advice.  It only takes one slip up (in using clever methods) to wash away all the benefits.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...