program clean up

BlitzPlus Forums/BlitzPlus Programming/program clean up

luke101(Posted 2004) [#1]
Hello, I am trying to figure out if there is an easy way to release all resources when the program exits

Also wanted to know if there is a way to know when my blitz program window is minimized or not..I will appreciate any help


Stoop Solo(Posted 2004) [#2]
I believe all the resources are automatically freed upon program termination.


soja(Posted 2004) [#3]
Yes, if a program terminates, Windows automatically frees all the resources it gave it while it was running. Still, it's better to free a resource during runtime if you're not going to use it anymore. It will save you from possible memory leaks and perhaps a longer wait for the program to terminate.

That said, it's no big deal if it's just references here and there... but if you're creating a ton of types in a loop or something that you only use once each, well, that's another issue.

And for your second question, you can use the WinAPI function GetWindowPlacement to determine whether your window is minimized or not. An example follows. Move the window around and min/max it and see what happens. You'll notice that ShowCmd is 2 when the window is minimized.

; .lib "user32.dll"
; GetWindowPlacement%(hwnd%, pwpl*):"GetWindowPlacement"

CreateTimer(1)
w = CreateWindow("WindowPlacement Test", 100, 100, 400, 400, 0, 3)

Repeat 
	Select WaitEvent()
		Case $803 : End
		Case $4001 : wp(QueryObject(w,1))			
	End Select
Forever

Function wp(hwnd)
	wp.WindowPlacement = New WindowPlacement
	wp\size = 11 * 4
	If Not GetWindowPlacement(hwnd, wp) Then
		Notify "Failed"
	Else
		Print "Flags: " + wp\flags
		Print "ShowCmd: " + wp\showCmd
		Print "MinPos: ("+wp\x_MinPos+","+wp\y_MinPos+")"
		Print "MaxPos: ("+wp\x_MaxPos+","+wp\y_MaxPos+")"
		Print "Rect: ("+wp\leftRect+","+wp\topRect+") - ("+wp\rightRect+","+wp\bottomRect+")"
		Print "-----------"
	EndIf
End Function

Type WindowPlacement
	Field size
	Field flags
	Field showCmd
	Field x_MinPos, y_MinPos
	Field x_MaxPos, y_MaxPos
	Field leftRect, topRect, rightRect, bottomRect
End Type



CS_TBL(Posted 2004) [#4]
I had the impression that B+ (or windows:) doesn't release all resources. I don't know if you can call it a resource, but before I rightfully free'd all stuff I got empty uh.. 'things' in my taskbar .. (those inverse button squares indicating an app, what's that name) Ofcoure, since my taskbar does auto-hide/never on-top, I run my app 20+ without noticing that new squares are added each time.. Eventually I had 50+ empty squares on my taskbar :)


soja(Posted 2004) [#5]
Windows will release the memory that was given to that process (and, of course, its threads, though that doesn't apply to Blitz) when it terminates, but if you launch any new processes, those are different. I'm not really sure what you're describing.


CS_TBL(Posted 2004) [#6]
well, maybe it's a 98se bug ..

I simply made some app with some gadgets here and there. And @ $803 I simply ended inmediately

(if eventid()=$803 end)

In that case, some [________] in the taskbar stayed there.. it's prolly the [________] that once belonged to the app I was running.

Nowadays I use a proper exit part to free-up stuff (like freeing the main window), and now the issue is gone.

So, at least in 98se not everything is cleaned-up after the program 'ends' !


soja(Posted 2004) [#7]
Interesting...

I suppose there would be differences between NT and 9x memory management. Now I'm curious.


Hotcakes(Posted 2004) [#8]
Yes there is. Every process is given it's own memory allotment, when a program ends, Windows frees it's allotment. All that's happenning there is that Win98 isn't telling the taskbar that the application no longer exists... Same happens in XP as well - if a program has an icon in the little section next to the clock and exits unexpectedly, the icon will only be cleared when you mouse over it (Windows tries to find what app the icon belongs to so it can bring up the little info bubble, realises it doesn't exist and acts accordingly)...

Just sloppy programming if you ask me. But it's Microslops, so what do you expect?


luke101(Posted 2004) [#9]
ok...i see..thanks alot