Bug 152613 - Macro Basic: RAM isn't deallocated when macro is finished
Summary: Macro Basic: RAM isn't deallocated when macro is finished
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.6.0.0 alpha0+
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Memory
  Show dependency treegraph
 
Reported: 2022-12-20 09:43 UTC by Kamil Landa
Modified: 2023-03-15 13:31 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kamil Landa 2022-12-20 09:43:15 UTC
Run LibreOffice and run some RAM Watcher - I use standard Task Manager via Ctrl+Alt+Del in Win10. 
Run macro devourRAM (it does recursion for array of various sub-arrays) for example only from Basic Editor - it isn't so fast, so it shows progressbar. It takes about 0,5 GB RAM. Check it in RAM Watcher. 
When macro will finish, the RAM will stay occupied :-(. You can close Basic IDE to have only LibreOffice Starter, but RAM is occupied. 
After you close whole LibreOffice then RAM is deallocated. 

-------------------

private gi&, gpOut() 'index and array for result

Sub devourRAM
	dim oDoc as object, i&, p(), oStatusbar, iStep&
	const j=20000 'increase this to devour more RAM
	oStatusbar=getController.StatusIndicator
	oStatusbar.start("It isn't so fast :-(", j)
	
	p=array(1, 2, 3, array(1, 2, 3, array(1, 2, 3), 4, array(1, 2, 3), 4, array(1, array(2, 3))), 4, array(1,2,3), array(1, 2, array(1,2), 3), _
		array(1, 2, 3, array(1, 2, 3, array(1, 2, 3), 4, array(1, 2, 3), 4, array(1, array(2, 3))), 4, array(1,2,3), array(1, 2, array(1,2), 3) ), _
		array(1, 2, 3, array(1, 2, 3, array(1, 2, 3), 4, array(1, 2, 3), 4, array(1, array(2, 3))), 4, array(1,2,3), array(1, 2, array(1,2), 3) ), _
		array(1, 2, 3, array(1, 2, 3, array(1, 2, 3), 4, array(1, 2, 3), 4, array(1, array(2, 3))), 4, array(1,2,3), array(1, 2, array(1,2), 3) ), _
		array(1, 2, 3, array(1, 2, 3, array(1, 2, 3), 4, array(1, 2, 3), 4, array(1, array(2, 3))), 4, array(1,2,3), array(1, 2, array(1,2), 3) ) )
	redim gpOut(130)
	for i=1 to j
		gi=0
		recurArray(p, "") 'recursion
		iStep=iStep+1 'for statusbar
		if iStep=10 then 'set new value
			oStatusbar.setValue(i)
			iStep=0
		end if		
	next i
	oStatusbar.reset
	gi=0
	gpOut()=0
End Sub

Function recurArray(level as variant, s$) 'recursion for reading the sub-arrays, output to global array gpOut
	dim i&
	if level(0)>0 then 'for the count of current word
		gpOut(gi)=array( s, level(0) ) 'add to global output array
		gi=gi+1
	end if
	for i=1+lbound(level) to ubound(level) 'next indexes in level
		if isArray(level(i)) then
			recurArray(level(i), s & i) 'get sub-level
		else
			gpOut(gi)=array( s, level(0) ) 'add to global output array
			gi=gi+1
		end if
	next i
End Function

Function getController() as object 'get oDoc.CurrentController for progressbar, also if only Basic IDE is running
	dim oDoc as object
	oDoc=ThisComponent
	if isNull(CreateUnoService("com.sun.star.reflection.CoreReflection").getType(oDoc)) OR _
	isNull(CreateUnoService("com.sun.star.script.Invocation").createInstanceWithArguments(array(oDoc))) then 'regular oDoc isn't, try to get other Libre window like Basic editor
		
		dim oComponents as object, oComponent as object
		oComponents=StarDesktop.Components.CreateEnumeration
		while oComponents.hasMoreElements 'try all Libre windows
			oComponent=oComponents.NextElement
			if oComponent.Identifier="com.sun.star.script.BasicIDE" then 'Basic Editor is active
				getController=oComponent.CurrentController
				exit function
			end if
		wend
		oDoc	=StarDesktop.LoadComponentFromUrl("private:factory/swriter", "_blank", 0, array()) 'open new document in Writer for progressbar
	else
		getController=oDoc.CurrentController
	end if
End Function

-----------------

Tested in:
Version: 7.4.3.2 (x64) / LibreOffice Community
Build ID: 1048a8393ae2eeec98dff31b5c133c5f1d08b890
CPU threads: 8; OS: Windows 10.0 Build 17763; UI render: Skia/Raster; VCL: win
Locale: cs-CZ (cs_CZ); UI: cs-CZ
Calc: CL

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: ad387d5b984c6666906505d25685065f710ed55d
CPU threads: 8; OS: Windows 10.0 Build 17763; UI render: Skia/Raster; VCL: win
Locale: cs-CZ (cs_CZ); UI: en-US
Calc: CL threaded
Comment 1 Buovjaga 2023-03-15 13:31:16 UTC
Repro

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 668c44e841a10cec8932a446a941e6d7c386bf3b
CPU threads: 2; OS: Windows 10.0 Build 22621; UI render: Skia/Raster; VCL: win
Locale: en-US (en_FI); UI: en-US
Calc: threaded