Well, that very last run you obviously didn't get less working set. So I take it, that's what excel 2013 occupies normally of memory - 180 millions Bytes???
The reading of the working set might indicate whether memory is freed or not. But it will be more a kind of assumption what's happening then knowing if the particular objects are removed from memory. That's if you run the code several times observing the development of working set:
- If there is a steady increase of memory allocation in my opinion it will indicate that memory isn't freed properly (but as to the number of calls been done for each run there will still be the chance that the piling is caused somewhere else)
- In case memory allocation from the first run to the last run doesn't increase at all, it will definitely tell that everything is fine (but that won't happen, as you said because of ongoing things in the background
- If memory allocation increases a small amount then you are left to guessing
Quote:
If you have any useful links to offer please throw them down here. I would be very grateful of that.
|
Seemingly you are quite familiar with API calls and doing great, me I don't, so maybe you make something of this:
The intention is to read from the created pointer in memory. Meaning storing ObjPtr in a public variable after setting an object, let it go out of scope and try to access the pointer seeing what's in there:
An example with a scalar:
Code:
Public lng_VarPtr As Long
Public lng_ObjPtr As Long
#If Win64 Then
Public Const PTR_LENGTH As Long = 8
#Else
Public Const PTR_LENGTH As Long = 4
#End If
Public Declare PtrSafe Sub Mem_Copy Lib "kernel32" Alias "RtlMoveMemory" ( _
ByRef Destination As Any, _
ByRef Source As Any, _
ByVal Length As Long)
' Platform-independent method to return the full zero-padded
' hexadecimal representation of a pointer value
Function HexPtr(ByVal Ptr As LongPtr) As String
HexPtr = Hex$(Ptr)
HexPtr = String$((PTR_LENGTH * 2) - Len(HexPtr), "0") & HexPtr
End Function
Public Function Mem_ReadHex(ByVal Ptr As LongPtr, ByVal Length As Long) As String
Dim bBuffer() As Byte, strBytes() As String, i As Long, ub As Long, b As Byte
ub = Length - 1
ReDim bBuffer(ub)
ReDim strBytes(ub)
Mem_Copy bBuffer(0), ByVal Ptr, Length
For i = 0 To ub
b = bBuffer(i)
strBytes(i) = IIf(b < 16, "0", "") & Hex$(b)
Next
Mem_ReadHex = Join(strBytes, "")
End Function
Sub ExampleForScalar()
Dim lngValue As Long
lngValue = 100
lng_VarPtr = VarPtr(lngValue)
Debug.Print "lngValue : 0x"; HexPtr(lng_VarPtr); _
" : 0x"; Mem_ReadHex(lng_VarPtr, 4)
End Sub
Sub ValueIsGone()
Debug.Print "lngValue : 0x"; HexPtr(lng_VarPtr); _
" : 0x"; Mem_ReadHex(lng_VarPtr, 4)
End Sub
In this example with ValueIsGone() you track down the pointer obtained from ExampleForScalar() and the reading of Memory says the value is zero.
Now with objects it isn't that easy, and that's where I'm struggling. I trying to recover the object from memory by it's pointer by adding this code:
Code:
Function ObjectFromPointer(lPtr As Long) As Object
Dim oTemp As Object
Mem_Copy oTemp, lPtr, 4
Set ObjectFromPointer = oTemp
End Function
Sub ExampleForObject()
Dim objRange As Object
Set objRange = Sheets(1).Range("A1")
lng_ObjPtr = ObjPtr(objRange)
'Set objRange = Nothing
End Sub
Sub ObjectIsGone()
Dim objRecover As Object
Set objRecover = ObjectFromPointer(lng_ObjPtr)
End Sub
But Mem_Copy in the function ObjectFromPointer() is killing the excel application, no debugging but killing,
so be careful with that one.
I'm assuming that the pointer maybe doesn't exist anymore, which would be fine, indicating that the object was taken from memory, but we can have that proof with excel going to hell.
Any idea on this?
As I said, I'm not doing well with API, I basically got my wisdom from this page:
http://bytecomb.com/vba-scalar-varia...ters-in-depth/