Upgrade to Pro — share decks privately, control downloads, hide ads and more …

メモリリークに関するウワサの今昔

 メモリリークに関するウワサの今昔

動作確認のサンプルコードあります https://github.com/woshidan/MemoryLeakTest

懇親会や下記の記事にていただいたご指摘を元に、
Viewに渡すContextの部分をApplicationContextからActivityContextに訂正させていただきました。
非常に丁寧にまとめられていてとても勉強になりました。

http://ytrino.hatenablog.com/entries/2016/05/26

ありがとうございます。

D849a9a1268bf7b840d1eb762873f7ca?s=128

woshidan

May 25, 2016
Tweet

More Decks by woshidan

Other Decks in Programming

Transcript

  1. GMO Pepabo, Inc. Woshidan 2016/05/25 potatotips #29 ϝϞϦϦʔΫʹؔ͢ Δ΢ϫαͷࠓੲ

  2. ࣗݾ঺հ !XPTIJEBO (.0ϖύϘ CMPH IUUQXPTIJEBOIBUFOBCMPHDPN "OESPJE׳Ε͖͔ͯͨ΋

  3. ϝϞϦϦʔΫରࡦͰ ͙͙ͬͯग़ͯ͘Δ͜ͱ

  4. ϝϞϦϦʔΫରࡦͰ͙͙ͬͯग़ͯ͘Δ͜ͱ 7JFXͷίʔυ্ͰҾ਺ͷ$POUFYU͸Մೳͳ ݶΓ"QQMJDBUJPO$POUFYU<> ಺෦Ϋϥε͸֎෦ΫϥεͷϓϩύςΟ͕ෆཁ ͳΒՄೳͳݶΓTUBUJDʹ͢Δ<> 3FDZDMFS7JFXͷ"EBQUFSΛ֎͢<> #JUNBQͷϝϞϦΛ໌ࣔతʹղ์<> ࢖Θͳ͘ͳͬͨΠϕϯτϦεφΛղ์͢Δ<>

  5. ͍·΋ຊ౰ʹඞཁ

  6. -FBL$BOBSZ <><> Ͱࢼͯ͠Έͨ

  7. ϝϞϦϦʔΫରࡦͰ͙͙ͬͯग़ͯ͘Δ͜ͱ 7JFXͷίʔυ্ͰҾ਺ͷ$POUFYU͸Մೳͳ ݶΓ"QQMJDBUJPO$POUFYU<> ಺෦Ϋϥε͸֎෦ΫϥεͷϓϩύςΟ͕ෆཁ ͳΒՄೳͳݶΓTUBU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εͨ΍Γ͗͢Ͱޡݕ ग़  ࠷ॳ͸͜ͷลΛ͓୊ʹ͠Α͏ͱ͍ͯͨ͠ͷͰࣦ᪨͠ Α͏͔ͱࢥͬͨ جຊతʹ"DUJWJUZ$POUFYUͰΑ͍Ͱ͢

    <><>
  12. ϝϞϦϦʔΫରࡦͰ͙͙ͬͯग़ͯ͘Δ͜ͱ 7JFXͷίʔυ্ͰҾ਺ͷ$POUFYU͸Մೳͳ ݶΓ"QQMJDBUJPO$POUFYU<> ಺෦Ϋϥε͸֎෦ΫϥεͷϓϩύςΟ͕ෆཁ ͳΒՄೳͳݶΓTUBUJDʹ͢Δ<> 3FDZDMFS7JFXͷ"EBQUFSΛ֎͢<> #JUNBQͷϝϞϦΛ໌ࣔతʹղ์<> ࢖Θͳ͘ͳͬͨΠϕϯτϦεφΛղ์͢Δ<>

  13. ࣮ݧ'"#ͷΫϦοΫϦεφ "DUJWJUZPO$SFBUF GBCTFU0O$MJDL-JTUFOFS OFX$VTUPN$MJDL-JTUFOFS  "DUJWJUZPO%FTUSPZͰ͸Կ΋͠ͳ͍ DMBTT$VTUPN$MJDL-JTUFOFSJNQMFNFOUT7JFX0O$MJDL-JTUFOFS\ !0WFSSJEF QVCMJDWPJEPO$MJDL 7JFXW

    \ PQFO3FDZDMFS7JFX W  ^ ^
  14. ࣮ݧ݁Ռ

  15. ϦʔΫ͕֬ೝͰ͖ͳ ͔ͬͨ

  16. ࣮ݧ ͰϝϞϦϦʔΫ͠ͳ͍ཧ༝ "OESPJEͷHBSCBHFDPMMFDUJPO͸ϚʔΫΞ ϯυεΠʔϓํࣜ<> ϧʔτͱͳΔΦϒδΣΫτ͔Β࠷୹ͷด࿏Λ࡞ΔΑ͏ʹ ΦϒδΣΫτಉ࢜ͷࢀরπϦʔΛ࡞੒<> ϧʔτͱͳΔͷ͸"DUJWJUZ 4FSWJDF ΫϥεΦϒδΣΫτͳͲʜ<> ੜଘ͍ͯ͠ΔϧʔτΦϒδΣΫτͱͦͷࢠΛϚʔΫͯ͠

    ͍͘<><> ϚʔΫ͞Εͳ͔ͬͨΦϒδΣΫτΛ($Ͱղ์͢Δ<> ࢠͷཁૉ͔ΒḷΕΔ͍ͣΕ͔ͷϧʔτͷΦϒδΣΫτ͕ੜ ଘ͍ͯͨ͠ΒɺੜଘʹϚʔΫ͞Εͯ($͞Εͳ͍<><>
  17. ࣮ݧ ͰϝϞϦϦʔΫ͠ͳ͍ཧ༝ ٯʹɺϧʔτΦϒδΣΫτʹ౰ͨΔ΋ͷ͕ ͢΂ͯੜଘ͍ͯ͠ͳ͚Ε͹($͞ΕΔ ΠϕϯτϦεφ΍3FDZDMFS7JFX "EBQUFS ͷ৔߹ͷϧʔτΦϒδΣΫτ͸ɺ"DUJWJUZ ଞʹαʔϏεͳͲ͔Βࢀর͍ͯ͠ͳ͔ͬͨΒ"DUJWJUZ ͕ੜଘͱͯ͠ϚʔΫ͞Εͳ͔ͬͨΒ͜ΕΒ΋ϚʔΫ͞ Εͳ͍

    ($͞Ε͓͔ͯ͘͠ͳ͍ɺϦʔΫ͠ͳͯ͘౰વ
  18. ͳͥϝϞϦϦʔΫ͠ͳ͍ͷʹ ͜ΕΒͷ͜ͱ͕ϝϞϦϦʔΫͷ࿩Ͱ ݕࡧ͢Δͱग़ͯ͘Δͷ͔

  19. ੲ͸ϝϞϦϦʔΫ͠ͳͯ͘΋ ࡉ͔͘ϝϞϦΛ؅ཧ͔ͨͬͨ͠

  20. "OESPJEΑΓલ d೥ ($ʹؔ͢Δ͢΂ͯͷ޻ఔͰΞϓϦͷ͢ ΂ͯͷεϨου͕ࢭ·ͬͨ<> ΦϒδΣΫτͷϚʔΫͱεΠʔϓʹ࣌ؒ ͕͔͔Γɺ($ͷఀࢭ࣌ؒ͸ඵΛ௒ ͑Δ͜ͱ͕͟Βͩͬͨ<> ͜·ΊʹࢀরΛ੾͓ͬͯ͘͜ͱͰɺੜଘ͍ͯ͠ ΔΦϒδΣΫτ͔ΒͷϚʔΫΛૣ͔ͨͬͨ͘͠

  21. "OESPJEҎ߱ ೥d ($ͷओཁͳ޻ఔ͕ΞϓϦͷओཁͳεϨο υͷॲཧͱฒߦͯ͠ߦ͑ΔΑ͏ʹͳͬͨ <> ΦϒδΣΫτͷϚʔΫͱεΠʔϓʹϚϧ νίΞ$16ͷԸܙ͕ड͚ΒΕΔΑ͏ʹ ͳΓɺఀࢭ͕࣌ؒ୹͘ͳͬͨ<> ࡉ͔͍ϝϞϦ؅ཧΑΓ($Ͱճऩ͞Εͳ͍ϝϞϦ ϦʔΫʹؔ৺͕Ҡͬͨ

  22. "DUJWJUZ͕ϦʔΫ͠ʹ͘͘ͳͬͯΔ XJEHFUΫϥεͳͲͷϝϞϦϦʔΫ͸͠ ͹͠͹"OESPJE։ൃऀͷ(PPHMFHSPVQ ͷ.-ͳͲʹใࠂ͞Ε͍ͯΔ<><> %SBXBCMF͕͍࣋ͬͯͨ$BMMCBDLͷΠϯελϯ ε͕"OESPJEҎ߱Ͱऑࢀরʹมߋ͞ΕΔ ͳͲमਖ਼͞Ε͍ͯΔ΋ͷ΋͋Δ<> ੲ͸ϦʔΫ͚ͨ͠Ͳɺ͍·͸ϦʔΫ͠ͳ ͍ه๏΋͋Δ<>

  23. 6*ͷΠϕϯτϦεφͷղ์ ʹ͍ͭͯ͸ݱࡏ͸Ҏલ΄Ͳؾ ʹ͠ͳͯ͘΋ྑͦ͞͏

  24. ଞͷ࿩΋ͦ͜·Ͱؾʹ͠ ͳ͍͍ͯ͘

  25. ϧʔτΦϒδΣΫτ͕ "DUJWJUZͱҧ͏ͷ͸ ૬มΘΒͣ஫ҙ͕ඞཁ

  26. ྫ͑͹

  27. #JUNBQ /BUJWFͷϝϞϦ؅ཧΛ͍ͯ͠Δ෦෼ ͕͋Γ<><>ɺ*NBHF7JFXͷଐੑͳͲ Ͱͳ͘ίʔυͰ؅ཧ͢Δ৔߹͸ެࣜͷ υΩϡϝϯτ<>ʹैͬͯ஫ҙ͢Δ ࣗ৴͕ͳ͚Ε͹1JDBTTP<> (MJEF<> ͳͲͷϥΠϒϥϦΛ௨ͯ͠ѻ͏

  28. ଞʹ͸௕࣌ؒͷ)BOEMFS <> ΍"TZOD5BTL <> ͳͲ

  29. "TZOD5BTL ඇTUBUJDͳ಺෦Ϋϥεʹ͢Δͱݺͼग़͠ݩ "DUJWJUZ΁ͷࢀরΛ͍࣋ͬͯΔͷͰɺ࣮૷ ͢Δͱ͖͸TUBUJDʹ͢Δ<> ݺͼग़͠ݩ"DUJWJUZʹͭͳ͕Δࢀর͸ऑࢀ রͰ<><> ݺͼग़͠ݩ"DUJWJUZͷPO%FTUSPZͰ "TZOD5BTLDBODFM USVF <>

    ͜ͷลɺ3Y+BWB<>ʹஔ׵͢Δͱ؆୯ʹॻ͚Δ
  30. ·ͱΊ

  31. ϝϞϦϦʔΫʹؔ͢Δ΢ϫαͷࠓੲ "DUJWJUZΛϧʔτΦϒδΣΫτͱ͢Δ6* ͷΠϕϯτϦεφͷղ์ʹ͍ͭͯ͸ݱࡏ ͸ͦ͜·Ͱਆܦ࣭ʹͳΒͳ͍͍ͯ͘ XJOEPX5PLFOͷऔಘ΍5IFNFͷҾ͖ܧ͗ͳ ͲͷͨΊɺجຊతʹ"DUJWJUZ$POUFYUΛ<> #JUNBQͷѻ͍΍"TZOD5BTLͳͲʹͭ ͍ͯ͸Ҿ͖ଓ͖஫ҙ͢Δ

  32. αϯϓϧίʔυஔ͍ͯ·͢ IUUQTHJUIVCDPN XPTIJEBO.FNPSZ-FBL5FTU

  33. ࢀߟ <>IUUQBOESPJEEFWFMPQFSTCMPHTQPUKQBWPJEJOHNFNPSZMFBLTIUNM <>IUUQRJJUBDPNFUFUFUFUJUFNTBGFEFDF⒎EDCG <>IUUQEIBUFOBOFKQIJEFDIFDL <>IUUQTUBDLPWFSqPXDPNRVFTUJPOTSFNPWFBOPODMJDLMJTUFOFS <>IUUQTHJUIVCDPNTRVBSFMFBLDBOBSZ <>IUUQRJJUBDPNSFKBTVQPUBSP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ΫτͷπϦʔͷྫ

  39. ϦʔΫ͢ΔΦϒδΣΫτͷπϦʔͷྫ

  40. ϦʔΫ͢ΔΦϒδΣΫτͷπϦʔͷྫ "DUJWJUZͷΠϯελϯε͕ϦʔΫ͢Δ αϯϓϧίʔυ4UBUJD'JFME-FBL"DUJWJUZ

  41. )FBQ%VNQ΋ ͋ΔΑ

  42. େࡶ೺ͳݟ͚ͭํ "OESPJE4UVEJPͷ"OESPJE .POJUPSͷ.FNPSZλϒΛ։͘

  43. େࡶ೺ͳݟ͚ͭํ "DUJWJUZͷىಈͰϝϞϦ͕૿͑ͨޙɺ ͦͷ"DJUJWUZΛऴྃͤͯ͞ɺτϥοΫ Ϙλϯ ($ Λdճԡͯ͠($ͤͯ͞ ΋άϥϑʹग़͍ͯΔϝϞϦͷมԽΛݟ Δ )FBQ%VNQΛݟͯҟৗʹͨ͘͞Μ Πϯελϯεͷ͋ΔΫϥεΛ୳͢

  44. )FBQ%VNQͷྫ ո͍͠ίʔυΛ༻ҙ 3FDZDMFS7JFXͷ"EBQUFSΛ ղ์ͯ͠ͳ͍

  45. )FBQ%VNQͷྫ ո͍͠"DUJWJUZΛԿճ͔ىಈऴྃ͢ Δͱʜ

  46. )FBQ%VNQͷྫ ը໘ӈଆͷϝχϡʔ͔Β$BQUVSF "OBMZTJTΛ։͘

  47. )FBQ%VNQͷྫ ʮ%FUFDU-FBLFE"DUJWJUJFTʯͰϝ ϞϦϦʔΫͷ͋Δ"DUJWJUZ͕Θ͔Δ

  48. )FBQ%VNQ஫ҙ "OESPJE4UVEJPͷπʔϧ͸͍·઀ଓ தͷ୺຤Λ؂ࢹͯ͠Δ πʔϧͰ؂ࢹͯ͠Δ୺຤։ൃ༻୺຤ ͸͍͍ͩͨΞϓϦ͕Πϯετʔϧ͞Ε ͔ͯΒͷܦա͕࣌ؒ୹͍ ΞϓϦͷΠϯετʔϧ࣌ʹ͸ΞϓϦ͕ ࢖༻͢ΔϝϞϦྖҬ͕ॳظԽ͞ΕΔ