1. Gimmy Susan
  2. PowerBuilder
  3. Monday, 22 January 2018 11:04 AM UTC
Hello to all
I need to import in PB some data coming from some excel sheets.

I do this:
a cycle that is repeated N times with a FOR in which: I create, read and destroy excel.

The problem is that excel in the task manager does not disappear, and after 10/20 loops the program runs out of memory and crashes because i have 10/20 excel.

I noticed that N copies of excel disappear when I close the windows (not application) why?

What am I doing wrong ?

I attach code

thank you

Gimmy

 

================================================================================

 

string ls_
long ll_excel_rows, iii
int li_rtn
string ls_range
oleobject lole_excel, lole_workbook, lole_worksheet
 
for iii = 1 to 3
lole_excel = create oleobject
li_rtn = lole_excel.ConnectToNewObject("excel.application")
if li_rtn <> 0 then
MessageBox( "Error", 'Error running MS Excel api.')
destroy lole_Excel
else
  lole_excel.WorkBooks.Open("C:\a\006-20171206103943269000-03678.xls") 
 
  lole_workbook = lole_excel.application.workbooks(1)
  lole_worksheet = lole_workbook.worksheets(1)
 
  // Get the cell value
ls_ = lole_worksheet.cells(1,1).value 
  
  // Quit
  lole_excel.application.quit()
  lole_excel.DisconnectObject()
 
  destroy lole_Excel
end if
next
 
 
Accepted Answer
Gimmy Susan Accepted Answer Pending Moderation
  1. Tuesday, 23 January 2018 08:34 AM UTC
  2. PowerBuilder
  3. # Permalink

I solved the case.

I bring the solution for those who need it. I added a 'garbagecollect()' after the destroy thx

Comment
There are no comments made yet.
Ashutosh Varshney Accepted Answer Pending Moderation
  1. Monday, 22 January 2018 15:34 PM UTC
  2. PowerBuilder
  3. # 1

That sounds familiar! In my case, I was running my app from the IDE and disconnectobject did not really shutdown excel. But once I quit the IDE, all excel tasks were cleared. Good news is that this was not an issue running from the exe.

Hope that helps.

Comment
  1. Ashutosh Varshney
  2. Monday, 22 January 2018 15:41 PM UTC
And one more thing... you do not need to create your lole_excel in the loop. Create it once before you begin the loop and then destroy after everything has been completed.



Hope this helps.

  1. Helpful
There are no comments made yet.
Brad Mettee Accepted Answer Pending Moderation
  1. Monday, 22 January 2018 13:38 PM UTC
  2. PowerBuilder
  3. # 2

Have you tried destroying the sheet and workbook variables?

Comment
  1. Brad Mettee
  2. Monday, 22 January 2018 15:03 PM UTC
Wish I could edit prev reply, here's more to think on.



Check into using the workbook.close() function. It looks like you're not doing enough cleanup after using the Excel sheets, and they're staying in memory because of it.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.