In this example I will create and free 32 images by doubling the static ID specific when calling CreateImage(). The time needed by this function will on average double for each subsequent call:
** Note all examples were compiled and run using PureBasic for x64:
Code: Select all
id=1
Repeat
DisableDebugger
start=ElapsedMilliseconds()
CreateImage(id,1,1)
EnableDebugger
FreeImage(id)
Debug "Id/Elapsed: "+Str(id)+"/"+Str(ElapsedMilliseconds()-start)
id*2
If id=4294967296
Debug "Done!"
End
EndIf
ForEver
Code: Select all
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304
8388608
16777216
33554432
67108864
134217728
268435456
536870912
1073741824
2147483648
At first I thought that all numbers lower than a specified ID are always allocated but this is not the case. This can be demonstrated by performing the same loop but in reverse. The program runs and finishes almost instantly with none of the delay or large amount of memory consumption:
Code: Select all
id=4294967296
Repeat
DisableDebugger
start=ElapsedMilliseconds()
CreateImage(id,1,1)
EnableDebugger
FreeImage(id)
Debug "Id/Elapsed: "+Str(id)+"/"+Str(ElapsedMilliseconds()-start)
id/2
If id=1
Debug "Done!"
Repeat
Delay(1)
ForEver
EndIf
ForEver
This is not problem created by CreateImage() and can be demonstrated equally with OpenWinodw()/CloseWindow().
I don't know what the cause of this is but I did not expect to find PureBasic to consuming gigabytes of memory when allocating a few IDs.