WebView: fixed memory leak in cache.add(), give system memory back each time parse ends

git-svn-id: svn://kolibrios.org@8425 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-12-16 16:30:39 +00:00
parent 7f757d3058
commit 6cb7bf1eb6
6 changed files with 19 additions and 17 deletions

View File

@ -304,6 +304,11 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
Paint();
NewLine();
list.count = draw_y;
DrawBuf.bufh = math.max(list.visible, draw_y);
debugval("DrawBuf.bufh", DrawBuf.bufh);
buf_data = realloc(buf_data, DrawBuf.bufh * DrawBuf.bufw * 4 + 8);
list.CheckDoesValuesOkey();
anchors.current = NULL;
custom_encoding = -1;

View File

@ -41,7 +41,7 @@
// DATA //
// //
//===================================================//
char version[]="WebView 3.04";
char version[]="WebView 3.06";
#define DEFAULT_URL URL_SERVICE_HOMEPAGE
@ -231,10 +231,12 @@ void main()
if (http_get_type==PAGE) {
history.add(http.cur_url);
cache.add(http.cur_url, http.content_pointer, http.content_received, PAGE);
LoadInternalPage(http.content_pointer, http.content_received);
free(http.content_pointer);
LoadInternalPage(cache.current_buf, cache.current_size);
}
else if (http_get_type==IMG) {
cache.add(cur_img_url, http.content_pointer, http.content_received, IMG);
free(http.content_pointer);
GetImg(false);
}
}

View File

@ -26,6 +26,9 @@ void _cache::add(dword _url, _data, _size, _type)
url.add(_url);
size.add(_size);
type.add(_type);
current_buf = data_pointer;
current_size = _size;
}
bool _cache::has(dword _link)

View File

@ -54,7 +54,6 @@ void main()
}
@SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
@SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP);
loop() switch(@WaitEvent())
{
case evMouse: edit_box_mouse stdcall (#ed); break;

View File

@ -128,26 +128,22 @@ void DrawBufer::Show(dword _y_offset, _h)
void DrawBufer::IncreaseBufSize()
{
static dword alloc_counter;
static dword bufh_initial;
dword alloc_size;
dword free_ram_size;
char error_str[256];
if (!buf_data) {
alloc_counter = 1;
bufh_initial = bufh;
alloc_size = bufw * bufh * 4 + 8;
alloc_size = bufh * bufw * 4 + 8;
buf_data = malloc(alloc_size);
}
else {
alloc_counter++;
bufh = bufh_initial * alloc_counter;
alloc_size = bufw * bufh * 4 + 8;
} else {
if (bufh_initial != bufh) bufh_initial = bufh;
bufh += 4096*1600/bufw; //+50 Mb
alloc_size = bufh * bufw * 4 + 8;
buf_data = realloc(buf_data, alloc_size);
Fill(alloc_counter - 1 * bufw * bufh_initial * 4 + 8, fill_color);
Fill(bufh_initial * bufw * 4 + 8, fill_color);
}
bufh_initial = bufh;
free_ram_size = GetFreeRAM() * 1024;
if (alloc_size > free_ram_size) {
sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size - free_ram_size/1048576);
@ -156,5 +152,4 @@ void DrawBufer::IncreaseBufSize()
}
#endif

View File

@ -106,9 +106,7 @@ void load_lib()
void main()
{
int btn;
//dword cpu_frequency = GetCpuFrequency()/1000;
load_lib();
@SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP);
@SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
loop() switch(@WaitEventTimeout(50))
{