Advertisement
Guest User

finalizersP6

a guest
Jan 31st, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. about "finalization":
  2.  
  3. becouse discusion keeps to be DESTROYed by GC:
  4.  
  5. TL;DR: (current) GCs are wrong subsystem to implement
  6. "finalization" feature
  7.  
  8. teoretically:
  9.  
  10. "finalization" is considered part of object "destroing"
  11. which is simetric to object "creation", which includes object
  12. "initialization"
  13.  
  14. so "finalization" aka "cleanup" is symetric to "initialization"
  15. and eg. connecting to db is thinked as part of object
  16. initialization...
  17.  
  18. <dreaming>
  19. ...so programmers constantly requests general, automagic,
  20. per object resource management feature (not tied to 'try'
  21. block like 'finally' in C++)
  22.  
  23. {
  24. $dbh = setup_db(params);
  25. <code> ... <code>;
  26. #commented becouse not needed anymore
  27. #$dbh.cleanup(); # yay! \o/
  28. }
  29.  
  30. LEAVE works for simple (lexical) cases (like in *inside*
  31. setup_db routine).
  32.  
  33. but whould be realy nice if such cleanup was *guaranteed*
  34. to fire up instantly and exactly after last $dbh object
  35. ocurrence (last as in runtime...)
  36. </dreaming>
  37.  
  38. IMHO things are messed in industry becouse gc was
  39. available and already was tracing live objets so was
  40. simply reused for (delayed!no guaranee!object
  41. resurection!) finalization...
  42.  
  43. ref counting works too :) cycles strike again...
  44.  
  45. but (maybe) if SSA analysis (or other smart thing) happens early
  46. it could detect that object is no more reachable so it could insert
  47. cleanup routine. or maybe macro could automagically insert routine
  48. only in last object ocurrence ?
  49.  
  50.  
  51. that would be good for single actions like file/db handlers closing.
  52. but how about geekosaur++ double file syncing (two actions),
  53. or more complex actions, eg. which must happen in specific order?
  54. tree of actions so new layer maybe or just proper design...
  55.  
  56.  
  57. so GC object lifetime management is low level, specialized and
  58. automatic but resources are broader category and have usage
  59. tied to domain objects which can be more complicated eg. can
  60. require immediate action or special ordering
  61.  
  62.  
  63. Notes:
  64.  
  65. - RAII is for exceptional resource handling
  66. - finalizers are supoused to do cleanup before object destruction but
  67. resource management with finalizers is considered anti-pattern (becouse
  68. they are executed as part of (postponed) destruction by gc)...
  69. - dispose pattern is tied to lexical scope like LEAVE and can be missed during
  70. refactoring, etc
  71. - http://en.wikipedia.org/wiki/Finalizer#Problems quite a list, really needs
  72. some invention... or decoupling from GC or separate threatment
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement