memory-leaks

HttpClient spike in memory usage with large response

让人想犯罪 __ 提交于 2019-12-21 17:10:55
问题 I'm working on a console app that take a list of endpoints to video data, makes an HTTP request, and saves the result to a file. These are relatively small videos. Because of an issue outside of my control, one of the videos is very large (145 minutes instead of a few seconds). The problem I'm seeing is that my memory usage spikes to ~1 GB after that request is called, and I eventually get a "Task was cancelled" error (presumably because the client timed out). This is fine, I don't want this

memory leak unit test c++

风流意气都作罢 提交于 2019-12-21 16:56:18
问题 I have just resolved a memory leak in my application and now I want to write a unit test to ensure that this does not happen again. I'm look for a way to detect the memory usage of the current application (working set), before and after some functions. For example: long mem_used= GetMemUsed(); /* Do some work */ /* clean up */ if( mem_used != GetMemUsed() ) { Error( "Memory leek" ); } I have found plenty of ways to detect the memory usage across the entire system but none for just the current

Why do you have to call delete for local variables of a function that are stored in the heap?

丶灬走出姿态 提交于 2019-12-21 12:57:39
问题 Suppose that you have the following function: void doSomething(){ int *data = new int[100]; } Why will this produce a memory leak? Since I can not access this variable outside the function, why doesn't the compiler call delete by itself every time a call to this function ends? 回答1: Why will this produce a memory leak? Because you're responsible for deleting anything you create with new . Why doesn't the compiler call delete by itself every time a call to this function ends? Often, the

Is there any reasonable use of a function returning an anonymous struct?

淺唱寂寞╮ 提交于 2019-12-21 12:19:37
问题 Here is an (artificial) example of using a function that returns an anonymous struct and does "something" useful: #include <iostream> template<typename T> T* func(T* t, float a, float b) { if(!t) { t = new T; t->a = a; t->b = b; } else { t->a += a; t->b += b; } return t; } struct { float a, b; }* foo(float a, float b) { if(a==0) return 0; return func(foo(a-1,b), a, b); } int main() { std::cout << foo(5,6)->a << std::endl; std::cout << foo(5,6)->b << std::endl; void* v = (void*)(foo(5,6)); //

Why .data() function of jQuery is better to prevent memory leaks?

我是研究僧i 提交于 2019-12-21 12:04:18
问题 Regarding to jQuery utility function jQuery.data() the online documentation says: "The jQuery.data() method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks. " Why to use: document.body.foo = 52; can result a memory leak -or in what conditions- so that I should use jQuery.data(document.body, 'foo', 52); Should I ALWAYS prefer .data() instead of using expandos in any case? (I would appreciate if you can provide

New empty iOS app has dozens of memory leaks

廉价感情. 提交于 2019-12-21 11:36:08
问题 Using the Leaks Instruments tool on a new, from-scratch, one-view iOS app reports 23 leaks. This doesn't seem right — am I missing something? Repeated runs yield different leak counts, from 16 to 35. Steps to reproduce follow this screenshot. A similar, unanswered question, was posted at Memory leak in login with amazon sample ios app I'm using Xcode 10.2.1 (10E1001); iOS 12.2 (Simulator & device both show leaks, with or without Reveal activated.) Create fresh one-view iOS app. In Scheme >

Memory Leak Using JSON-C

荒凉一梦 提交于 2019-12-21 09:31:50
问题 I am new to JSON-C, Please see my sample code and let me know of it will create any memory leak, if yes then how to free JSON-C object. struct json_object *new_obj = NULL; new_obj = json_tokener_parse(strRawJSON); new_obj = json_object_object_get(new_obj, "FUU"); if(NULL == new_obj){ SYS_OUT("\nFUU not found in JSON"); return NO; } new_obj = json_object_object_get(new_obj, "FOO"); // I m re-using new_obj, without free it? if(NULL == new_obj){ SYS_OUT("\nFOO not found in JSON"); return NO; } /

How to avoid memory leak with shared_ptr and SWIG

可紊 提交于 2019-12-21 09:25:13
问题 I'm trying to use boost::shared_ptr 's to allow for me to use c++ file I/O stream objects in my python script. However, the generated wrapper warns me that it is leaking memory. Here's a minimal .i file exhibiting the problem: %module ptrtest %include "boost_shared_ptr.i" %include "std_string.i" %shared_ptr( std::ofstream ) %{ #include <fstream> #include <boost/shared_ptr.hpp> typedef boost::shared_ptr< std::ofstream > ofstream_ptr; ofstream_ptr mk_out(const std::string& fname ){ return

How should I free an array of objects in a Delphi 7 destructor?

天大地大妈咪最大 提交于 2019-12-21 09:21:38
问题 Suppose my Delphi classes look like this: interface type TMySubInfo = class public Name : string; Date : TDateTime; Age : Integer; end; TMyInfo = class public Name : string; SubInfo : array of TMySubInfo; destructor Destroy; override; end; implementation destructor TMyInfo.Destroy; begin // hmmm.. end; end. To properly clean up, what should go in the destructor? Is it enough to do SetLength(SubInfo,0) , or do I need to loop through and free each TMySubInfo ? Do I need to do anything at all?

Can a Redux store lead to a memory leak?

别说谁变了你拦得住时间么 提交于 2019-12-21 09:19:55
问题 I have a dashboard application with several charts getting updated on a set interval. My first thought was to update the data in the store and then let all charts feed from there. But could that lead to a memory leak? Since Redux creates a new store every time the data changes and keeps the old ones. Would a ~2mb data every second pile up and crash the application? The alternative I see is to keep the data in the local state (with setState). I hope some more experienced React/Redux devs can