memory-management

how to retain view after addSubview of UIViewController with ARC

自作多情 提交于 2020-01-02 13:28:09
问题 How to handle situation when I use ARC and add view of UIViewController? MyViewController *vc = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil]; [someView addSubview:vc.view]; //this retain vc.view because addSubview retain onlu view, not controller, so controller is released. Before ARC there was a way to retain controller as long as neede, but how to prevent ARC to release View Controller? 回答1: I had similar situation solved by declaring vc as property with default

Deallocating vector of pointers, but memory still in use

混江龙づ霸主 提交于 2020-01-02 10:49:07
问题 I have no idea what's wrong with the following code! I am deleting all pointers, but when I use the "top" command to watch the memory, I can see that still lots of memory is allocated to the program. Am I missing something here to free the memory? #include <iostream> #include <vector> using namespace std; int main() { vector<int*> container; vector<int*>::iterator itr; unsigned long long i; for(i = 0; i < 10000000; i++) { int* temp = new int(); *temp = 1; container.push_back(temp); } for(itr

Deallocating vector of pointers, but memory still in use

大城市里の小女人 提交于 2020-01-02 10:47:30
问题 I have no idea what's wrong with the following code! I am deleting all pointers, but when I use the "top" command to watch the memory, I can see that still lots of memory is allocated to the program. Am I missing something here to free the memory? #include <iostream> #include <vector> using namespace std; int main() { vector<int*> container; vector<int*>::iterator itr; unsigned long long i; for(i = 0; i < 10000000; i++) { int* temp = new int(); *temp = 1; container.push_back(temp); } for(itr

Memory leakage issue in FORTRAN when allocating an array inside a subroutine and passing it back

北城余情 提交于 2020-01-02 10:33:57
问题 I am using pointers to pass some arrays to a subroutine and then allocate that array inside that subroutine and send it back to the first subroutine. In one module I have something like this: module call_test subroutine bla use test double precision, dimension(:), pointer :: xyz ! interface boink subroutine boink(a) implicit none double precision, dimension(:), pointer :: a end subroutine boink end interface boink ! call boink(xyz) deallocate(xyz) end subroutine bla end module call_test and

Lua - Count the no. of references to a table

橙三吉。 提交于 2020-01-02 10:22:31
问题 The Lua docs say When a program has no references to a table left, Lua memory management will eventually delete the table and reuse its memory. My question is : Is it possible to count the no of references to a particular table during runtime? 回答1: You can find all references to a Lua value using the debug library. See these messages: http://lua-users.org/lists/lua-l/2012-03/msg00479.html http://lua-users.org/lists/lua-l/2012-04/msg00758.html The luatraverse library found in the below link

Lua - Count the no. of references to a table

烂漫一生 提交于 2020-01-02 10:21:29
问题 The Lua docs say When a program has no references to a table left, Lua memory management will eventually delete the table and reuse its memory. My question is : Is it possible to count the no of references to a particular table during runtime? 回答1: You can find all references to a Lua value using the debug library. See these messages: http://lua-users.org/lists/lua-l/2012-03/msg00479.html http://lua-users.org/lists/lua-l/2012-04/msg00758.html The luatraverse library found in the below link

Xcode Memory Leaks detection in Unit Test

假装没事ソ 提交于 2020-01-02 08:47:11
问题 Is it possible to test if memory leaks occur when running a Unit Test? I want to check if my memory management is handled correctly. Thanks 回答1: You can try running your unit tests under Instruments with the Leak Detection Instrument. However, this will only work for Application (bundle) tests, if you're using OCUnit. If you happen to use something else, please let us know. 来源: https://stackoverflow.com/questions/6570384/xcode-memory-leaks-detection-in-unit-test

Do I need to free memory returned from a C function called via CFFI?

落爺英雄遲暮 提交于 2020-01-02 07:53:48
问题 I have this example code that has a function text() returning a newly allocated string: ffi_test = FFI() ffi_test.set_source('_test', ''' char* test() { return strdup("hello world"); } ''') ffi_test.cdef(''' char* test(); void free(void *); ''') ffi_test.compile(verbose=True) This works fine: In [1]: from _test import ffi, lib In [2]: x = lib.test() In [3]: ffi.string(x) Out[3]: b'hello world' In [4]: lib.free(x) However, I could not find anything in the docs whether I actually need to

When to Py_INCREF?

我的梦境 提交于 2020-01-02 07:20:28
问题 I'm working on a C extension and am at the point where I want to track down memory leaks. From reading Python's documentation it's hard to understand when to increment / decrement reference count of Python objects. Also, after couple days spending trying to embed Python interpreter (in order to compile the extension as a standalone program), I had to give up this endeavor. So, tools like Valgrind are helpless here. So far, by trial and error I learned that, for example, Py_DECREF(Py_None) is

Should I use Pools for particles if i forced to re-init every particle every time i create them

一曲冷凌霜 提交于 2020-01-02 06:27:14
问题 I am creating a particle system in XNA4 and I've bumped into problem. My first particle system was a simple list of particles, whose instances are created when needed. But then I read about using pools. My second system consists of a pool, filled with particles, and an emitter/controller. My pool is pretty basic, this is the code: class Pool<T> where T: new () { public T[] pool; public int nextItem = 0; public Pool(int capacity) { pool = new T[capacity]; for (int i = 0; i < capacity; i++) {