It is currently Mon Dec 16, 2019 6:52 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [Done] HTTPRequest() with Header$() eats memory
PostPosted: Tue Mar 19, 2019 2:35 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4468
Location: Germany
Hi,

I've written a program which gets very often data from a REST-API.
If I look with Taskmanager or ProcessExplorer the memory usage growth rapidly without an end.

I cut it down to a problem of a user Header$():
Code:
NewMap Header$()

InitNetwork()

Header$("Authorization") = "Bearer "

Repeat

  HttpRequest = HTTPRequest(#PB_HTTP_Get, "https://www.purebasic.com", "", 0, Header$())
  ;HttpRequest = HTTPRequest(#PB_HTTP_Get, "https://www.purebasic.com")
  If HttpRequest
    Response$ = HTTPInfo(HTTPRequest, #PB_HTTP_Response)
    FinishHTTP(HTTPRequest)
  Else
    Debug "Request creation failed"
  EndIf
 
  Delay(3000)
 
ForEver


If you change the commented line, the memory usage is 'normal'.

@Fred
Do you use curl_slist_free_all() ?

P.S.: Since I run into many problems with the new HTTP procedures and with the missing possibility to set the timeout,
I decided to use again my libcurl.pbi instead.


Top
 Profile  
Reply with quote  
 Post subject: Re: HTTPRequest() with Header$() eats memory
PostPosted: Tue Mar 19, 2019 2:59 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4468
Location: Germany
This works witout growing memory:
Code:
IncludeFile "libcurl.pbi"

Define curl.i, *CurlSList.Curl_Slist, result$


InitNetwork()


Repeat
 
  curl = curl_easy_init()
  If curl
    *CurlSList = curl_slist_append(#Null, "Content-Type: application/json")
    *CurlSList = curl_slist_append(*CurlSList, "Accept: application/json")
    curl_easy_setopt(curl, #CURLOPT_HTTPHEADER, *CurlSList)
   
   
    curl_easy_setopt_str(curl, #CURLOPT_URL, "https://www.purebasic.com")
   
    ; follow a redirection automatically
    curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 1)
   
    ; accept insecure certificates
    curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0)
    curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0)
   
    ; to put the header inside the received data
    curl_easy_setopt(curl, #CURLOPT_HEADER, 1)
   
    ; use own receive function
    curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @LibCurl_WriteFunction())
   
    If curl_easy_perform(curl) = #CURLE_OK
      result$ = LibCurl_GetData()
    EndIf
   
    curl_slist_free_all(*CurlSList)
    curl_easy_cleanup(curl)
  EndIf
 
  Delay(3000)
 
ForEver


Top
 Profile  
Reply with quote  
 Post subject: Re: HTTPRequest() with Header$() eats memory
PostPosted: Wed Apr 10, 2019 8:00 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13663
Location: France
Fixed.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye