![]() |
#13
|
|||
|
|||
![]()
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:
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 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 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/ |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Wierd "script code" in a downloaded .doc file | CNBarnes | Word | 2 | 10-18-2012 02:07 AM |
![]() |
krishnaoptif | Word VBA | 9 | 06-22-2012 05:08 AM |
![]() |
Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |
Rules and Alerts: "run a script"? | discountvc | Outlook | 0 | 06-15-2010 07:36 AM |
An "error has occurred in the script on this page" | decann | Outlook | 8 | 09-03-2009 08:54 AM |