But at the time of execution, a visit to a 5 KB port, about 2000 times the memory is 50 m, very egg pain,
Code:
H_Session,
H_Connect,
H_Request: Pointer;//the unit within the global variable
While true do
The begin
Submit;
Sleep (5);//5 millisecond delay time
The end;
Procedure Submit;
The begin
H_session:=WinHttpOpen (nil, WINHTTP_ACCESS_TYPE_NO_PROXY, nil nil, WINHTTP_FLAG_ASYNC);
WinHttpSetStatusCallback (h_session, AsyncCallBack, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS, 0);
H_connect:=WinHttpConnect (h_session, PChar (' c.tieba.baidu.com '), and urls. The port, 0).
H_request:=WinHttpOpenRequest (h_connect, PChar (' GET '), PChar ('/c/s/filluname), PChar (' HTTP/1.1), nil, nil, 0).
WinHttpSendRequest (h_request, nil, 0, nil, 0, 0, 0).
The end;
The callback function code;
Procedure AsyncCallBack (hInternet: Pointer; DwContext: DWORD; DwInternetStatus:
DWORD. LpvStatusInformation: Pointer; DwStatusInformationLength: DWORD); Stdcall;
Var
Res: TMemoryStream;
Size: DWORD;
Buff: an Array of Char [1.. 4096].
The begin
Case dwInternetStatus of
WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE:
The begin
WinHttpReceiveResponse (hInternet, nil);
The end;
WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE:
The begin
WinHttpSetStatusCallback (hInternet, nil, 0, 0);
Try
Res:=TMemoryStream. Create;
Size:=0;
While WinHttpReadData (hInternet @ Buff, 4096, the Size) do
The begin
If the Size & lt;=0 then Break;
Res. Write (Buff [1], the Size).
Size:=0;
The end;
The finally
If Assigned (hInternet) then WinHttpCloseHandle (hInternet);
FreeAndNil (Res);
The end;
The end;
WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING:
The begin
If Assigned (hInternet) then WinHttpCloseHandle (hInternet);
The end;
The end;
The end;
CodePudding user response:
Background resources will not immediately released, details see below,http://stackoverflow.com/questions/12652868/winhttpopen-leaking-memory
CodePudding user response: