Page 2 of 4

Re: My app slows down other apps?

Posted: Sun Jul 14, 2024 10:41 am
by BarryG
Hi infratec. So is the way I'm currently doing it wrong ("Global kernel32=")?

Also, is "CloseHandle_(snap)" needed? Snap isn't a handle, is it? It's a return value of doing a function in an opened handle? So confused.

Re: My app slows down other apps?

Posted: Sun Jul 14, 2024 10:47 am
by infratec
https://learn.microsoft.com/en-us/windo ... 32snapshot
If the function succeeds, it returns an open handle to the specified snapshot.
No, you can do it with CallFunction, but it is more to type and your parameters are not checked.

Re: My app slows down other apps?

Posted: Sun Jul 14, 2024 10:50 am
by BarryG
I meant "snap" when used with CallFunction() isn't a handle; it's a return value with 0 meaning error.

Anyway, I guess I will have to convert all my library calls to the way you mentioned. Thanks!

Re: My app slows down other apps?

Posted: Sun Jul 14, 2024 10:59 am
by infratec
According to the help it returns the value of the called function or 0 if there is no such function available.
So it returns #INVALID_HANDLE_VALUE or the open handle.

Re: My app slows down other apps?

Posted: Sun Jul 14, 2024 11:05 am
by BarryG
But #INVALID_HANDLE_VALUE = -1, which is not an error and not a handle?

Re: My app slows down other apps?

Posted: Sun Jul 14, 2024 11:16 am
by infratec
Look at my example.
I told you to check the value <> #INAVLID_HANDLE_VALUE

Re: My app slows down other apps?

Posted: Sun Jul 14, 2024 11:26 am
by infratec
You should do:

Code: Select all

If snap <> 0 and snap <> #INVALID_HANDLE_VALUE
And inside call CloseHandle_(snap) at the end.

Re: My app slows down other apps?

Posted: Sun Jul 14, 2024 11:32 am
by BarryG
Okay, thank you. Appreciate your help again. 8)

Also, I noticed my app has "GetModuleHandle_(0)" a lot in it. However, MSDN says this returns a handle to the module. So I should be using FreeLibrary_() with it when done, yes? I haven't been doing that.

I also had AddAtom_() without a corresponding DeleteAtom_() in there that was being called regularly. Fixed that now.

Process Explorer is working well to show me the handle count in real time while I'm debugging this issue. Some of my changes so far have stopped it rising so fast, so I'm obviously on the right track. :)

Re: My app slows down other apps?

Posted: Sun Jul 14, 2024 11:49 am
by spikey
BarryG wrote: Sun Jul 14, 2024 11:32 am So I should be using FreeLibrary_() with it when done, yes?
Don't do that. GetModuleHandle doesn't adjust the reference count, FreeLibrary does. You'll cause problems in the targetted processes sooner or later. Stick with CloseHandle in this case.

Re: My app slows down other apps?

Posted: Mon Jul 15, 2024 10:19 pm
by BarryG
I seem to have fixed the handle issue (after 24 hours of running, the handle count is only 587, which is drastically down from 41811 the other day). However, the slowdown is still occurring despite this. :( Looks like I still have a lot of investigating to do.

Re: My app slows down other apps?

Posted: Mon Jul 22, 2024 10:14 am
by BarryG
This is so weird. I just tried using "ResMon" in Windows to suspend my app, and even though suspended, other apps (like Calc in my first post) still open and draw their GUI slowly. But if I quit my app, they open fast again. So now I'm struggling to understand why my system-suspended app STILL has an effect on other third-party app behaviour. It's like it has a hold on them somehow.

I read this -> https://superuser.com/questions/1273959 ... tasking-bu

And noticed what it said about GDI objects. Mine has 2600 of them (and growing slowly), which I assume is bad? I know how some are created (I do use "CreateDC" a lot), but is there anything specific that I should be doing other than just freeing them when done? I'm going through my code to make sure all these are done -> https://www.deleaker.com/blog/2021/12/1 ... -fix-them/

Re: My app slows down other apps?

Posted: Mon Jul 22, 2024 10:38 am
by Fred
Yes, it's bad, it shouldn't be growing at all, that's probably the issue

Re: My app slows down other apps?

Posted: Mon Jul 22, 2024 11:23 am
by BarryG
Every GetDC_() should have a ReleaseDC_(), yes? I had lots of those without releasing, so I just added a release to them all.

(In my defense, a lot of those were copied codes from other people here ;) ).

Re: My app slows down other apps?

Posted: Mon Jul 22, 2024 11:35 am
by DarkDragon
BarryG wrote: Mon Jul 22, 2024 11:23 am Every GetDC_() should have a ReleaseDC_(), yes?
After painting with a common DC, the ReleaseDC function must be called to release the DC. Class and private DCs do not have to be released. ReleaseDC must be called from the same thread that called GetDC. The number of DCs is limited only by available memory.
https://learn.microsoft.com/en-us/windo ... user-getdc

It depends.

Re: My app slows down other apps?

Posted: Mon Jul 22, 2024 11:53 am
by BarryG
DarkDragon wrote: Mon Jul 22, 2024 11:35 amIt depends.
Sh*t. :( Any harm in just releasing them if all imagery related to them is still valid?