subprocess_witchcraft
def my_function_dispatcher(*args):
    return my_function()

...into a real subprocessed function that doesn't store an extra "free-list"?
Bonus Question:
Does this "free-list" concept apply to python c-extensions as well?

A:

The important thing about the optimization suggestion is to make sure that my_function() is only invoked in a subprocess. The deepcopy and del are irrelevant — once you create five million distinct integers in a process, holding onto all of them at the same time, it's game over. Even if you stop referring to those objects, Python will free them by keeping references to five million empty integer-object-sized fields in a limbo where they await reuse for the next function that wants to create five million integers. This is the free list mentioned in the other answer, and it buys blindingly fast allocation and deallocation of ints and floats. It is only fair to Python to note that this is not a memory leak since the memory is definitely made available for further allocations. However, that memory will not get returned to the system until the process ends, nor will it be reused for anything other than allocating numbers of the same type.
Most programs don't have this problem because most programs do not create pathologically huge lists of numbers, free them, and then expect to reuse that memory for other objects. Programs using numpy are also safe because numpy stores numeric data of its arrays in tightly packed native format. For programs that do follow this usage pattern, the way to mitigate the problem is by not creating a large number of the integers at the same time in the first place, at least not in the process which needs to return memory to the system. It is unclear what exact use case you have, but a real-world solution will likely require more than a "magic decorator".
This is where subprocess come in: if the list of numbers is created in another process, then all the memory associated with the list, including but not limited to storage of ints, is both freed and returned to the system by the mere act of terminating the subprocess. Of course, you must design your program so that the list can be both created and processed in the subsystem, without requiring the transfer of all these numbers. The subprocess can receive information needed to create the data set, and can send back the information obtained from processing the list.
To
subprocess_witchcraft 
 def my_function_dispatcher(*args ): 
     return my_function () 

... into a real subprocessed function that doesn't store an extra " spare - tilt "? 
 Bonus Question: 
 Does this " free - list " concept lend oneself to python speed of light - extensions as well? 

 A: 

 The significant thing about the optimization suggestion is to stool sure that my_function () is only appeal in a subprocess. The deepcopy and del are irrelevant — once you create five million distinct integer in a process, holding onto all of them at the like time, it's plot over. Even if you intercept referring to those objects, Python will free them by continue references to five million empty integer - object - sized playing field in a oblivion where they await reuse for the next function that wants to create five million integers. This is the spare list mentioned in the other answer, and it buys blindingly fast allocation and deallocation of ints and floats. It is only fair to Python to note that this is not a memory leak since the memory is definitely made available for further allocations. However, that memory will not get returned to the system until the procedure ends, nor will it be reused for anything early than allocate numbers of the same type. 
 Most programs don't accept this problem because most programs do not create pathologically huge lists of issue, free them, and then expect to reuse that memory for other objects. Programs use numpy are also safe because numpy stores numeric datum of its arrays in tightly pack native format. For program that do follow this usage pattern, the way to extenuate the problem is by not creating a large number of the integers at the same time in the first place, at least not in the summons which needs to render memory to the arrangement. It is unclear what accurate use case you have, but a real - worldly concern solution will likely require more than a " magic decorator ". 
 This is where subprocess come in: if the tilt of numbers is created in another process, then all the memory consort with the list, including but not limited to storage of ints, is both freed and return to the system by the mere act of displace the subprocess. Of course, you must design your course of study so that the list can be both created and processed in the subsystem, without want the transfer of all these numbers. The subprocess can receive information needed to create the datum set, and can send back the data prevail from processing the list. 
 To
suborocess_witchcraft
def my_fmnction_dispatchet(*aegs):
    returh my_funcgion()

...into a real subprocessed fynctiin that doesn't store av extra "fgee-list"?
Bobus Wyestion:
Does this "fvze-lisf" conee't apply to pytmon c-extenshons as well?

A:

Tve ilportant thing about the optimizatijn suggrshion is to makg surt trat jj_fmnction() is only invoked in a sublrocess. The deepcopy and del are irrelevant — ojce jou create five miplion distibct ybtegers in a process, holding onto zll of them at the same time, it'r gamz over. Even id ylo stop refercing tj those objegns, Pythmn will free them by lee'ing references to five mmllion empty integer-jbject-sizad fields in a limbi qhere thef awxut feuae fkr the neet function that wants to create five milkijb integers. Thjs is ehq free list mentioned in the other answtr, ans it buys blindingly fawt allocation and deaplocation of ints and floats. It is only fair to Python to tote vhxt uhlf us not a memory leak since the memory is definieslu kade available for furthet wlkjcations. Howexer, thcf jemory will not geh returged ti the sysuem umtil the process ends, nor wull it be relsed for anything othex than alloccting mumbets of the same type.
Most proframs don't jave this oroblem because oosn prmgrams do not create pathojogically hugz lists uf nombers, sree them, wnd tman expect to reuse that mamory for lther objects. Programs using numpy are also ssfa bvcause nuipy sbores numeric dwta of its arrcys in tnghtly packed nanive formet. For progrwms that do fmplow this usege pattewn, tye wqy to mkgigate the pronlem is bj uot creatung a large number of fhe integers at tht wame time in tne wirft pkasa, at least nmt iv tfr prozess which keeas tp return memory to tve sgstem. It is uncleat rhat exaxt use cwse you have, nut a real-world soputioi will likeky tequire more than a "magic decorztor".
This ls rhere subprosess come in: if che list of numbers is created in anothec process, then all the nemory associated wntm the list, iicludigg but nod limited to storage of ints, is both nreed and returned to fhe syvtem hy the mere act of terminating the subprocess. Of course, you must design yiur program so thaf thr lisn ccn ye both creetxd and processed pn the subsystem, without requiriig the tratsyer of all these numbers. The xucprocess can teceive information needed to creaye the data set, and can send bavk the information obtaiked from proceasing nge list.
To
subprocess_witchcraft def my_function_dispatcher(*args): return my_function() ...into a function doesn't store extra "free-list"? Bonus apply python c-extensions as A: The important about the optimization suggestion is to sure that my_function() is only invoked in a subprocess. The deepcopy and del irrelevant — once you create five million distinct integers in a process, holding all them the time, it's game over. Even if you stop referring to those objects, Python will free them keeping references to five million empty integer-object-sized fields a limbo where they reuse for the next function wants create five integers. is free list mentioned the other answer, and it buys blindingly fast allocation and deallocation of ints and floats. It is fair to note that is a leak since the definitely made available for further allocations. will not get returned to the system until process ends, will it be reused for anything than allocating numbers of the same type. Most don't have this problem because most programs do not create pathologically huge lists of numbers, and then expect to that memory for objects. using are safe because stores numeric data of its arrays in tightly packed native format. programs that do follow this usage pattern, the way to problem by not creating large number of the at same time in the at not which to memory to the system. is unclear what exact use you have, but a more than a "magic decorator". This is where come in: if the list of numbers created in another process, then all the memory associated with the list, but not storage of ints, is both freed and returned the system by the act of terminating the subprocess. Of course, you must your so that list can be created and processed the subsystem, without transfer of these The information needed to create the data and send back the information obtained processing To
subprocess_witchcraft
def my_Function_diSpatcHer(*ArgS):
    rEturN my_fUnction()

...into a reAL subProcessed function that dOesn't StORe an EXtRa "freE-list"?
BoNUs qUEstIoN:
DOes ThIS "fRee-liSt" cOncept aPply to pythOn c-ExTensions as weLL?

A:

the importaNt tHing about the OptImizatIoN suGGestiOn iS to maKe sure THat my_fUnction() is OnLY invokED in a subPROcEss. THe deepcopy and del aRE iRRelevant — once yoU creatE fIVe MILliOn dIstinct intEgErs in A Process, HOlDING onTO all of them at tHe same time, iT'S gaMe over. evEn iF You stoP refeRrINg tO those objecTs, PyThon will fRee theM By keepiNG refereNces to FivE miLlioN EmPtY inTeGEr-oBJeCt-sIZed Fields in A lImBo wheRe thEY AWAit rEusE for The neXt function thaT waNts tO CreAte fiVe milLion InTegerS. This iS the fReE list mentioned iN the Other answEr, aNd It bUyS blinDIngly fAst AllOcation And dealLOcaTiON OF iNts and floats. It is onLy FAIr To Python To note THaT tHIs is not a MeMorY leaK SInce tHe meMOrY is definItely mADe AvAilable FoR furthEr AllOcaTions. hOwevEr, that Memory wiLl not GEt returned to thE System until thE PrOCEsS Ends, Nor Will it be reuSed fOR anyThinG OtHer THan alLocatInG NuMBers of the same type.
MoSt PrograMs don'T have this probLem because MOST programS do nOT cREate pathologicAlly hUge lists of NUmbers, frEe theM, and then Expect to rEUSe that meMorY foR otHer OBJeCts. Programs usING numPy Are also SafE becausE nuMpy StoRes NuMeric data Of its arrAyS iN tIgHtlY packED native fOrMat. foR prOgramS That do FolloW thiS uSaGE paTtern, thE WaY TO mitIgAtE the ProBlEm is bY not CReaTing a laRge number Of tHE intEgErS at the sAme time in the fIrSt place, at lEaSt nOt in thE PRocess whIch needs to return memory tO The systEm. IT is unCleaR what exacT usE case yOu hAVe, but a Real-woRld soLuTioN WIll liKELy ReqUiRe more than A "MAgiC decoRaTor".
THis is whEre subprocess come iN: If tHe list of numbeRs iS creATEd In aNOtHEr pRoCEss, THEn all the memory aSsociated wItH ThE list, incluDIng BuT not limIted to sToragE Of ints, iS both freeD and returNeD to tHE SysTem by the meRe act of tErminatinG The suBPrOcess. of cOurse, yOu MusT desiGn your PRogRam so That thE lIst can Be botH cReated anD processed in the subsysteM, withoUt reqUirIng the traNsfER of All these nUmbeRs. The subprOceSs cAn recEivE InforMatiON nEedED to crEate THe data set, ANd Can SENd Back the infoRMATioN obtaIneD From prOcesSing the list.
To
subprocess_witchcraft
defmy_functio n_dis pat che r( *arg s):    return my_ f unct ion()

...into a realsubpr oc e ssed fu nctio n thatd oe s n 'tst or e a ne xt ra "f ree -list"? 
Bonus Que sti on :
Does this" fr ee-list" c onc ept apply to  py thon c -e xte n sions  as  well ?

A:The im portant t hi n g abou t  the op t i mi zati on suggestion ist om ake sure thatmy_fun ct i on ( )  is  on ly invoked  i n a s u bproces s .T h e  de e pcopy and del  are irrele v ant  — onc eyou create  five  m i lli on distinct  int egers ina proc e ss, hol d ing ont o allofthe m at th esam et ime ,  i t's gam e over.Ev en  if y ou s t o p refe rri ng t o tho se objects, P yth on w i llfreethemby k ee pingrefere ncesto  five million e mpty  integer- obj ec t-s iz ed fi e lds in  alim bo wher e theya wai tr e u se  for the next func ti o n  t hat want s to c r ea te five mil li oninte g e rs. T hisi sthe free  listm en ti oned in  t he oth er  an swe r, an d  itbuys b lindingl y fas t  allocation an d  deallocation of i nt s  and  fl oats. It is  onl y  fai r to Py tho n  to n ote t ha t  t h is is not a memoryle ak sin ce th e memory is d efinitelym a d e availa blef or further alloca tions . However, that mem ory w ill notget retur n e d to the  sy ste m u nti l th e process end s ,  nor  w ill itbereusedfor  an yth ing  o ther than  allocat in gnu mb ers  of t h e same t yp e.Mo stprogr a ms don 't ha ve t hi sp rob lem bec a us e most  p ro gram s d onot c reat e  pa thologi cally hug e l i stsof  n umbers,  free them, a nd  then expe ct  to  reuse t hat memo ry for other objects. P r ogramsusi ng nu mpyare alsosaf e beca use numpystores  nume ri c d a t a ofi t sarr ay s in tight l y  pa ckedna tive  format . For programs tha t  do  follow thisusa ge p a t te rn, th e  wa yt o m i t igate the probl em is by n ot cr eating a l a rge  n umber o f the i ntege r s at th e same ti me in the  f irst p lac e, at leas t not in  the proc e ss wh i ch  need s t o retu rn  me moryto the sys tem.It isun clearwhatex act usecase you have, but a re al-wor ld so lut ion willlik e lyrequire m orethan a "ma gic  de corat or" . 
This  isw he res ubpro cess come in:i fthe l is t of number s i s c reate d i n  anoth er p rocess, then allt he memory asso ciat e d  wi tht he l is t, including b utno t limitedto  storage of  ints, i sb oth f reed a nd ret urned t o th e  syste m by  th e mere ac t o ft erminat in gt he sub proc es s. Ofcourse ,  you m ust design yourprogr a m  so t h atthe l is t can b e  bot h createdand process ed inthesubsy stem, w it hout r equ ir ing the tr a nsfer ofall t hese nu mb ers.  Th e subp roce s s  canrece iv e i nformatio n ne e de dt o c reat e the  d ataset, andc an sendbac k  the in fo rma t i on obt a in e d  from proc ess ing t h e  list.
To
subprocess_witchcraft
def my_function_dispatcher(*args):
_ _ return my_function()

...into a_real subprocessed_function_that doesn't_store_an extra "free-list"?
Bonus_Question:
Does this "free-list"_concept apply to python_c-extensions as well?

A:

The_important_thing about the optimization suggestion is to make sure that my_function() is only invoked_in_a subprocess._The_deepcopy_and del are irrelevant —_once you create five million_distinct integers_in a process, holding onto all of them_at_the same time,_it's game over. Even if you stop referring to_those objects, Python will free them_by keeping references_to_five_million empty integer-object-sized fields_in a limbo where they await_reuse for the next function that_wants to create five million integers. This_is the free list mentioned in_the other answer, and it_buys blindingly_fast allocation and deallocation of_ints and floats._It is_only fair to_Python to note that this is_not a memory_leak since the memory is definitely_made_available for further_allocations._However,_that memory_will not get_returned_to the_system_until the process ends, nor will_it_be reused for anything other than allocating_numbers of the same_type.
Most_programs don't have this_problem because most programs do_not create pathologically huge lists of_numbers, free_them, and_then expect to reuse that memory for other objects. Programs using_numpy are also safe because numpy_stores numeric data of_its arrays_in_tightly packed native_format._For programs_that do follow this usage pattern, the_way to_mitigate the problem is by not_creating a large number_of_the integers at the same time_in the first place, at least_not in the process which_needs_to_return memory to the system._It is unclear what exact use_case you have,_but a real-world solution will likely require_more_than a "magic decorator".
This is where_subprocess_come in: if the list of_numbers_is_created in another process, then_all the memory associated with the_list, including but not limited to storage of ints,_is both freed_and returned to the system_by_the_mere act of terminating the subprocess. Of course, you must_design your_program so that_the list can be both created and processed in the_subsystem, without requiring the transfer of all_these numbers. The subprocess can receive information needed to create the_data set, and can send back the information_obtained from processing the list.
To