w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
occur memory leak when import uuid
Not a leak. Setting gc.DEBUG_LEAK causes the garbage collector to append even collectable objects to the garbage list instead of freeing them. You can see that everything the collector found was freeable, since all the messages say collectable.

Categories : Python

Return a char pointer (memory leak)
Since I assume you are on a linux system using GCC to compile you could use valgrind to run your program and guarantee to find any leaks present or even possible memory leaks that could happen. To answer your question more directly in this specific case, if you can guarantee that you free() receive after you are done using it then you will not have a memory leak. However, if you forget to free() receive and then reassign something to receive, that right there is considered a memory leak. You have lost the handle to the resource you were responsible for freeing and it can no longer be freed. In general, your code is very C-like and not the C++ way of doing things. Returning a std::string would be more C++-like. In regards to dynamic allocation, malloc() and free() are also the "C way" of

Categories : C++

Catching a memory leak in a shared pointer?
Each of your shared pointers keeps track of its own separate reference count. This is obviously no good. When one is destroyed, the ref count on the others is not updated. You need to keep the reference count in a separate location that all the shared pointers have access to.

Categories : C++

char pointer is struct array memory leak
How are you measuring the amount of memory occupied by the program? One thing off the top of my head is that you're looking at the size of the working set the OS is keeping track of. Since you've allocated and freed a lot of memory, the size of that set has increased. Some OSs will adjust the size of the working set after a while, some won't. What OS are we looking at here?

Categories : C

Memory Leak with Single Method
In java, the usual cause of excessive memory usage, is objects being allocated and not destroyed, in some sort of loop, such as a game loop. Are you adding to a dynamic array/list of sorts in a loop? Also, if a method takes a while, this effect can happen with local variables before they are destroyed.

Categories : Java

Dynamic Memory Allocation with pointer arrays
You're giving yourself way too much to do in one go. Break the problem down and test each component: Parse user input: Produce either a valid size_t integer or abort. Check that the value is neither zero nor too large, or abort. Suppose you've parsed the value n. Allocate memory for n copies of your structure: Dados * data = malloc(n * sizeof(Dados)); At the end, release the memory: free(data); Use proper parsing with error handling to populate each array member data[i]. Practice file operations separately.

Categories : C

How to release correctly memory in iOS: Memory is never released; potential leak of memory pointed to by
You need to free the bytes, because NSData does not take ownership of it: it cannot know if the array is a temporary or a dynamic, so it makes a copy of it. To fix this problem, replace return [NSData dataWithBytes:bytes length:c]; with NSData *res = [NSData dataWithBytes:bytes length:c]; free(bytes); return res;

Categories : IOS

python threads, multithreading with threading.thread
receive() never end because of endless loop; thread does not start. Start thread first. if instruction == "do work": threading.Thread(target=work).start() recieve() and drop () from threading.Thread(target=work()).start(). work() make work function call run in main thread.

Categories : Python

Release memory by using correct method in JNI to prevent memory leak
Do I need to release mConnectEnv, s_jObj, jmethodConnect ? static JNIEnv* mConnectEnv = 0; static jobject s_jObj; static jmethodID jmethodConnect; mConnectEnv: No but this is a misfeature in your code. JNIEnv * is provided by JNI, not by you. TYou should not be storing this in a static variable at all, you should use the one provided in the JNI call, or else call AttachCurrentThread() to get a new one. s_jObj: Yes. You need to free it some time with DeleteGlobalRef(). jMethodConnect: no. MethodIDs are not objects and do not need to be released. Therefore when I release j_ip, I used deleteLocalRef, I think this way is wrong! Should I use the ReleaseStringUTF method ? You don't need to to anything. All jobjects that you acquire during a JNI method call are released automatica

Categories : Android

How to release memory in android to avoid memory leak
There are a few notorious examples of memory hogs, with media (audio/video) and large bitmaps being the biggest memory hogs. Most things are taken care of by removing all pointers to them and letting GC have its way with them. Bitmaps, however, can be recycled more immediately by using: if (yourBitmap != null) { yourBitmap.recycle(); youBitmap = null; } Your media should be stopped and de-referenced. But it should be stopped in onPause(), and not left until onStop().

Categories : Android

Find memory leak using Eclipse memory analyzer
Did you try to compare 2 hprof file in MAT ? There is an option "Compare to another Heap Dump" in histogram view. It will show you the difference between 2 hprof file, and then it will be easier to find out your memory leak

Categories : Android

Is Django ModelFormSet using up all my memory? Similar to a memory leak
Sorry to answer my own question. I couldn't find this information pointed out clearly anywhere else, and hopefully this Q/A will be helpful to others. Yes, MyModelFormSet is pulling every "MyModel" from the database. I verified this in a test environment which had 15,000 MyModels in the database. I observed the following: 1) I submitted only 3 MyModels forms in a HTTP post. After the post: 2) formset.forms contains 3 MyModelForms. 3) len(formset._queryset) equals 15,000. formset._queryset contains a list of every MyModel in the database. Django has pulled every MyModel and stored it in memory. The solution is to provide a queryset argument. You can read more about this in the Django documentation. This test was performed with Django version 1.4.5.

Categories : Django

in memory mergeChangesFromContextDidSaveNotification and save memory leak
How big is this leak? How frequent? If the leak is inside of Core Data (as it appears) and it is small, there may be nothing you can do about it other than filing a radar. I would suggest that you switch over to using the parent/child context design instead of using the NSManagedObjectContextDidSaveNotification as that is faster, doesn't block the main thread and probably will solve your memory leak to boot. Update 300Mb in allocation is not a leak. Allocation is how much memory your application is using when it is running. If your leak is tiny (which it appears is the case) and it is inside of Core Data itself, there is nothing to be done about it as it is not worth chasing down.

Categories : Osx

Confusion on when should we use "single-pointer" and when "pointer-to-pointer" regarding datastruture
In this case, the pointer to pointer is used so that it is possible to change the pointer to the first node. You keep a pointer which points to the beginning of the list. If you add a new item, that pointer might need to change since the new item may be added at the beginning of the list. void insertAtBeginning(struct node **first_ptr,int value) { struct node *first = malloc(sizeof(struct node)); first->value = value; first->next = *first_ptr; *first_ptr = first; } void test() { struct node *first = 0; insertAtBeginning(&first,5); freeAll(first); } If you are doing something like searching through the list, there is no need to change the pointer to the first node, so there is no need to pass a pointer to pointer. But note that there are other us

Categories : C

Why does gevent use more memory than threading
Gevent is bound to use more memory as it maintains its own light weight threads (greenlets) which is bound to cause some overhead. If your application is CPU bound, then gevent might not be that useful for you. But if your application is I/O bound, then gevent is awesome as you can reach concurrency levels of 1000s on 4-8 GiG machine. Also as my friend once said, memory is expensive but not that expensive :-) Cheers!

Categories : Python

how do you accomplish multithreading using a single thread?
Coroutines are something done to simulate cooperative multithreading (not supported by .NET, unless we consider the async/await pattern to be a coroutine pattern). Asynchronous programming simulates multithreading (at least partially... More than one read/write for example is executed at the same time)... Both are possible solutions that hide the "threading" part. To elaborate on the asynchronous programming... One could build an entire web server, able to respond to hundred of requests at the same time, based on a single thread + asynchronous elaboration. Each read from the disk would be done asynchronously. Every response to the connecting clients would be done asynchronously and so on. To give a name, from what I comprehend, node.js is a single threaded web server entirely based on

Categories : C#

Concatenate arrays from foreach loop into single variable of nested arrays
Use this: $allimagesizes[] = $imagesizes; Putting [] after the array name means to add a new element to the end of the array. Also, in the assignment to $imagesizes, you should use =, not .=. The latter is for appending to a string.

Categories : PHP

Neo4j In memory configurations, multithreading, and slow writes
You cache arguments are invalid. node_cache_size=12G relationship_cache_size=12G node_cache_array_fraction=10 relationship_cache_array_fraction=10 These can only be used with the GCR cache. Setting the cache isn't going to put everything in memory for you at start up, you will have to write code to do this for you. Something like this: GlobalGraphOperations ggo = GlobalGraphOperations.at(graphDatabaseFactory); for (Node n : ggo.getAllNodes()) { for (String propertyKey : n.getPropertyKeys()) { n.getProperty(propertyKey); } for (Relationship relationship : n.getRelationships()) { } } Beware with the strong cache, if you have a lot of nodes/relationships, eventually your cache will become large and performing GC against it will cause long pauses in your system.

Categories : Neo4j

Why I have memory leak in C/MEX?
A_OUT seems to be a duplicate of R. Basically, according to the doc (that you should read before asking any question, just sayin' :) ), is creating a new array. Calling this function will allocate more memory to store this copy. So the leak is from A_OUT. You can use the valgrind tool to help you finding those, with the options --leak-check=full. Of course, compile with the debug flags of your compiler (-g3 for gcc), it will give you most of the informations you need to fix your leaks.

Categories : C

C++ Memory leak fix
What is the protocol for using some_func? Is the caller supposed to take ownership of the returned object? If so, it would be leaked. You need to push the obj returned by some_func onto the list, assuming the list takes ownership of the object. Indeed, using unique_ptrs here would help make this more clear.

Categories : C++

C++ Do I have memory leak?
Yes you do. In the assignment arr=temp; you overwrite the old pointer without freeing it. I would recommend not using raw pointers. Instead use std::unique_ptr< double[] > to wrap your pointers. It will guarantee that you won't leak. Example: std::unique_ptr< double[] > arr, temp; arr.reset( new double[++i] ); // in C++14 you would use std::make_unique instead

Categories : C++

SDL memory leak with TTF
You are calling TTF_RenderText_Solid() twice, yet you free the surface text created with it only once. On your second call: text = TTF_RenderText_Solid(font,str.c_str(),clr); you overwrite the pointer that points to the previous surface creating a memory leak. You do SDL_FreeSurface() the second surface but not the first one. Note: TTF_RenderText_Solid returns pointer to completely a new surface.

Categories : C++

Why I am getting memory leak
Window leaked exceptions are usually caused by dialogs which are not dismissed properly. ie if you are planning to dismiss a dialog in Onpostexecute of asynctask and the activity that created it has ended it will throw a window leak. Make sure you dimisss dialog in onPause of the activity.

Categories : Android

Is this a memory leak
Is this a memory leak? No, not really. The previous pages will be garbage-collected. If so can I fix it with SrchItemEditDetail.Content = null; That is of little use. The previous content will become unreachable anyway. But there are potential problems. When the Frame somehow keeps other references to a Content page (for example through an event) then you might have a leak. And when PageSearchFieldEnumMV holds resource you are not freeing them timely. In that case, or in any case to be safe, use: PageSearchFieldEnumMV nextPage = new PageSearchFieldEnumMV(...); if (SrchItemEditDetail.Content != null) SrchItemEditDetail.Content.Dispose(); // may need a typecast here SrchItemEditDetail.Content = nextPage;

Categories : C#

Want to pass a single char pointer from a double pointer
For simplicity's sake, you can assume a double pointer to be equivalent to a 2d array (it is not!). However, this means that you can use array-convention to access contents of a double pointer. #include <stdio.h> #include <string.h> char *query[5] = {"the","new","store","in","SF"}; char *stopwords[2] = {"the","in"}; char main_array[256]; void remove_stopwords(char **query,int query_length, char **stopwords, int stopwords_length); int main() { remove_stopwords(query,5,stopwords,2); puts(main_array); return 0; } void remove_stopwords(char **query,int query_length, char **stopwords, int stopwords_length) { int i,j,found; for(i=0;i<query_length;i++) { found=0; for(j=0;j<stopwords_length;j++) { if(strcmp(query[i]

Categories : C

Multithreading slower than singlethread in function with substantial memory access
Aside (since you seem to be talking about memory access and not allocation), the default malloc has poor performance if you are allocating memory in parallel. If you are looking for higher performance you may want to consider TCMalloc which scales significantly better with multithreaded allocations. In general, keeping shared memory synchronised between threads is a nightmare that should probably be avoided if possible. See if you can avoid cache invalidations by adopting a message-passing paradigm (this may not be possible for your use-case). Message passing with shared read-only memory is a good compromise for lowering cache traffic.

Categories : C

c# how can I sidestep the memory allocation bottleneck to improve multithreading performance
Its not a particularly a C# or .NET problem. For a CPU core to run optimally it needs all its data to be in the CPU cache. If a particular data is not in the CPU cache, a cache fault happens and CPU sit idle until the data is fetched from memory to Cache. If your in memory data is too much fragmented the chance of Cache fault increases. The way CLR does heap allocation is much more optimal for CPU cache. Its unlikely that you can achieve the same performance by handling the memory allocation yourself.

Categories : C#

Huge Memory and CPU usage with Multi-threading
Step 4 onwards doesn't make sense to me. I would suggest you stay with the multiple threads for the file loading and gathering information and also stay with the threads queuing the files and working out file lengths etc. The change I would make is to have a single consumer which reads from the playlist queue and actually plays the files, I don't see why you are using threads in this section. If using a single consumer doesn't work can you please expand on this and we'll try and assist.

Categories : C#

Main differences between threading with shared memory and MPI?
"Classic" threading shares all memory between the threads. This is rather dangerous, since it's very easy to accidentally modify data that another thread might be using, leading to nasty bugs. The onus is on the programmer to carefully protect data against unsafe access. This also (usually) requires all processes to be running on the same machine, with access to the same physical memory. Using independent processes with a message-passing interface gives you more control over which data is shared and which is private to each process; there is little or no danger of one process unexpectedly modifying another process's state. And as you say, the message passing interface can be generalised to pass messages across a network between processes on separate machines.

Categories : C++

C++ code memory leak
Since you can't find a straightforward leak, you seem to need to compare snapshots of memory state to see what has changed. A quick search indicates that valgrind's massif can do snapshots, and there's a python script to compare them (but probably you can compare by hand if your program is small)

Categories : C++

jQuery and memory leak in IE
Try .... $jQ.get(href.substring(0, (idx > 0 ? idx : href.length)) + '?random=' + Math.floor((Math.random()*1000000000)+1), replaceWithData }); .... function replaceWithData(data){ $jQ('#mainTable').replaceWith($jQ(data).find('#mainTable')); } For one of my projects, I deleted the "closures" because caused memory leaks (circular reference). see : http://www.codeproject.com/Articles/12231/Memory-Leakage-in-Internet-Explorer-revisited

Categories : Javascript

How to fix memory leak in SurfaceView
I found the workaround for this issue. You should simple call: getHolder().getSurface().release(); in your control from Activity's onDestroy() Something like this: class MyView { ... public void release() { getHolder().getSurface().release(); } ... } class MyActivity extends Activity { ... @Override public void onDestroy() { super.onDestroy(); mMyView.release(); } ... }

Categories : Android

possible to leak in-memory data from one ios app to another?
Theoretically once the user closes the app (you have to make sure that the app is closed and not just running in the background) the memory that was allocated to that process is deallocated and returned. To quote from a tutorial on ARC: "With Automatic Reference Counting enabled, the compiler will automatically insert retain, release and autorelease in the correct places in your program. You no longer have to worry about any of this, because the compiler does it for you." So when an app closes, all references to any objects which had some sort of memory allocation will be cleared because there will be no objects to reference when the app is not running. The reason that I say that you have to make sure that it is closed is because some apps, by default, will not close when you press the

Categories : IOS

Haskell: how to get rid of the memory leak
Mostly a guess, but your call to length xs to obtain n forces the spine of the input list xs, creating lots of thunks. For a quick test, use 1000 instead of dn and see if it helps. For full laziness, you could try to define normalize without having to pre-calculate the length of the list. But that is probably quite tricky to achieve... In your edited code I believe is no real space leak, just expensive data structures. The code runs much faster and in 133MB of ram after switching to unboxed vectors. Note how I had to change nothing but to add a few V. to functions: {-# LANGUAGE BangPatterns #-} import Data.List import Control.DeepSeq import qualified Data.Vector.Unboxed as V foldl'' f z (x:xs) = let z' = f z x in z' `deepseq` foldl'' f z' xs foldl'' _ z [] = z statistics :: [V.Vecto

Categories : Haskell

Valgrind memory leak
valgrind says that i'm leaking memory on the first line (Record* rec = new Record();). Why? Does it show the Record itself is being leaked, or something else allocated inside Record::Record? If the former, either some return path from MyClass::get_record leaks it, or the caller leaks it. Switching to use a smart pointer would fix both cases: std::unique_ptr<Record> MyClass::get_record (int id) { std::unique_ptr<Record> rec(new Record()); ... return rec; } If it's the latter case, that either means the whole Record is being leaked (see above), or its destructor is buggy. Again, try keeping any dynamically allocated members in smart pointers.

Categories : C++

NSDateFormatter memory leak?
Something you are doing right is init the NSDateFormatter before entering the loop. If you are expecting the same date format (MM/dd/yyyy) you can put in the same place you init it as well. It can be that you are allocating too many objects, so I could advise putting everything inside an @autoreleasepool {} (aka: the content of the loop inside the autorelease). I am seeing you are allocating the *newPoint inside the for and then you are setting the date to that object. What do you do after?

Categories : IOS

XS Memory leak in this code?
Well, the pattern of "create a template array, do av_make(), then free the template" is not very good -- you'd be much better by simply creating your array with newAV(), av_extend()ing it to the right size, and then doing av_store(newSVnv(...)) for each element. That lets you avoid the intermediate SVtempArray allocations entirely. However, that's not what you asked about. I think your problem is that you Safefree(SVArrays) without first sv_free()ing each element. Since av_make() duplicates the contents of the source array, AFAICT you're leaking the reference created by SVArrays[i] = newRV_noinc((SV*) av_make(count[i], SVtempArray)); You'll need to iterate over SVArrays and call sv_free() on each element before you Safefree(SVArrays).

Categories : C

Create a memory leak in .net?
for(int i = 0; i < 10; i++) { IntPtr imageData = Marshal.AllocHGlobal(1024*1024); } This will result in 10 MB leaked memory for example. Everything unmanaged can leak, its hard to get something managed to leak memory, if at all.

Categories : Dotnet

iOS drawInRect memory leak - ARC
You aren't calling UIGraphicsEndImageContext() at the end of your method. You should.

Categories : IOS

Getting memory leak in UIKit?
One easy way to detect where your leaks come from is to use the Extended Detail view of the Instruments. To do that click on "View"->"Extended detail" and a right menu with the stack trace of the "leak" will appear. There you will easily find the leaking code for each leak and if they come from your app.

Categories : IOS



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.