Questions tagged [resource-cleanup]

188 questions
89
votes
3 answers

How to delete all files older than 3 days when "Argument list too long"?

I've got a log file directory that has 82000 files and directories in it (about half and half). I need to delete all the file and directories which are older than 3 days. In a directory that has 37000 files in it, I was able to do this with: find *…
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
56
votes
7 answers

How can I get around the lack of a finally block in PHP?

PHP prior to version 5.5 has no finally block - i.e., whereas in most sensible languages, you can do: try { //do something } catch(Exception ex) { //handle an error } finally { //clean up after yourself } PHP has no notion of a finally…
Alistair Evans
  • 36,057
  • 7
  • 42
  • 54
44
votes
2 answers

Multiple defers vs deferred anonymous function

Is it safer or more idiomatic to issue multiple defer statements which are dependent on the order, or to defer an anonymous function which packages the logic? Examples: defer os.Remove(tempFile.Name()) defer tempFile.Close() In the case above the…
Vlad Didenko
  • 4,481
  • 4
  • 25
  • 34
26
votes
3 answers

Clean up Threejs WebGl contexts

I have a problem while cleaning up my WebGl-Scenes. I'm using Three.js with a WebGlRenderer. In my application I have to change the views quite often and therefore need to render new scenes all the time. Uptil now I destroy and reinitialize the…
kassette91
  • 275
  • 1
  • 3
  • 6
25
votes
9 answers

Automate process of Disk Cleanup cleanmgr.exe without user intervention

I am developing a powershell script file which shall execute some disk cleanup without user intervention. The user shall not be able to configure anything. When I run cleanmgr.exe /d c: sageset:1 a popup window appears to select files/folders to be…
Pinte Dani
  • 1,989
  • 3
  • 28
  • 35
24
votes
11 answers

Should objects delete themselves in C++?

I've spent the last 4 years in C# so I'm interested in current best practices and common design patterns in C++. Consider the following partial example: class World { public: void Add(Object *object); void Remove(Object *object); void…
Generic Error
  • 4,437
  • 6
  • 28
  • 26
22
votes
4 answers

Akka: Cleanup of dynamically created actors necessary when they have finished?

I have implemented an Actor system using Akka and its Java API UntypedActor. In it, one actor (type A) starts other actors (type B) dynamically on demand, using getContext().actorOf(...);. Those B actors will do some computation which A doesn't…
Robert Petermeier
  • 4,122
  • 4
  • 29
  • 37
21
votes
3 answers

If I set a variable using `CreateObject()`, do I need to clean it up by setting it to `Nothing` after use?

If I set a variable using CreateObject(), do I need to clean it up by setting it to Nothing after use? Dim foo Set foo = CreateObject("SomeAssembly") foo Bar Set foo = Nothing I just found this post by Eric Lippert: The script engine will…
Nick Strupat
  • 4,928
  • 4
  • 44
  • 56
15
votes
2 answers

Class wrapper around file -- proper way to close file handle when no longer referenced

I've got a class that wraps some file handling functionality I need. Another class creates an instance of the filehandler and uses it for an indeterminate amount of time. Eventually, the caller is destroyed, which destroys the only reference to the…
Spencer Rathbun
  • 14,510
  • 6
  • 54
  • 73
15
votes
2 answers

Do asynchronous context managers need to protect their cleanup code from cancellation?

The problem (I think) The contextlib.asynccontextmanager documentation gives this example: @asynccontextmanager async def get_connection(): conn = await acquire_db_connection() try: yield conn finally: await…
Maxpm
  • 24,113
  • 33
  • 111
  • 170
13
votes
2 answers

re-raising an exception in a context handler

From the datamodel docs on context managers: Note that __exit__() methods should not reraise the passed-in exception; this is the caller’s responsibility. I have a temporary file, whose file descriptor I'd like to free with close but without…
miku
  • 181,842
  • 47
  • 306
  • 310
11
votes
2 answers

Right way to close CloseableHttpResponse/CloseableHttpClient

I'm using CloseableHttpResponse (from apache-httpclient-4.5.3) and I'm not sure I'm using it right, I saw an answer with no votes to use EntityUtils.consume on finally: CloseableHttpResponse response1 = httpclient.execute(httpGet); try { …
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
11
votes
1 answer

How can I get CMake to allow for "make clean"ing just one target?

I have a project using CMake to generate Makefiles, which then get built with (GNU) make. In my project, the CMakeLists.txt defines two targets - but only one of them gets built when makeing after Makefile generation (e.g. using the…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
11
votes
2 answers

Disposable Resource Pattern

Is there anything standardized within the Scala library to support the disposable resource pattern? I mean something similar to that supported by C# and .NET just to mention one. For example does official Scala library provide something like…
Lord of the Goo
  • 1,214
  • 15
  • 31
10
votes
6 answers

How to clean node_modules folder when prepping for deployment

How would I go about cleaning the node_modules folder when prepping my code for deployment. I am making an app using node-webkit and would prefer to include the least amount of files possible when bundling the final version of the app as the unzip…
Hayko Koryun
  • 1,214
  • 2
  • 12
  • 30
1
2 3
12 13